• Create Account

## RenderMonkey and XNA 4.0

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Mytts  Members

106
Like
0Likes
Like

Posted 12 November 2012 - 04:46 AM

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):

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[i].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

### #2Mytts  Members

106
Like
0Likes
Like

Posted 13 November 2012 - 02:35 AM

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...

### #3NightCreature83  Members

4785
Like
0Likes
Like

Posted 13 November 2012 - 02:58 AM

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

### #4Mytts  Members

106
Like
0Likes
Like

Posted 13 November 2012 - 04:06 AM

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!

Edited by Mytts, 13 November 2012 - 05:04 AM.

### #5NightCreature83  Members

4785
Like
0Likes
Like

Posted 13 November 2012 - 08:11 AM

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

### #6Mytts  Members

106
Like
0Likes
Like

Posted 14 November 2012 - 05:08 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.