NickMcCrea

Hi all,

I've set myself the task of recreating a number of the example Dx9 effects in Rendermonkey as an exercise. Worked through a few of the simpler ones successfully, and gaining a good understanding of HLSL in the process.

Now, I think, I'll try the nifty refraction water effect, which is one of the examples under "reflection, refraction and water". It's the one with the skull underneath the disc of water.

Everything is going smoothly until, of course, I realise that volume textures are not supported. And that brings me to my questions that hopefully someone can answer.

1. Can such effects be recreated without volume textures I expect they can, I'm just not particularly familiar with HLSL yet. I'll post the pixel shader below, it's pretty short.

2. As for the reason for leaving out volume texture support, I do realise priorities must be made. I'd like to ask those of you who are a bit more experienced in this - is volume texture support a big deal, or a convenience

3. Has anyone modified the content pipeline to support volume textures

Here's the relevant pixel shader code from the effect I'm trying to recreate. Straight from the beating heart of the rendermonkey...the "Noise" sampler is the volume texture. Anyone familiar with this example Can the lack of volume texture support be worked around without massive hassle

float time_0_X: register(c0);
float4 color: register(c1);
sampler Noise: register(s1);
sampler renderTexture: register(s0);
const float3 offY = float3(0.31, 0.24, 0.43);
const float3 offZ = float3(0.47, 0.19, 0.78);

float4 main(float3 texCoord: TEXCOORD0, float3 eyeLinear: TEXCOORD1) : COLOR {
float3 noiseCoord = texCoord.xyz * 0.3f;
// 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;
}



Re: XNA Game Studio Express Volume textures, HLSL and re-creating rendermonkey effects

NickMcCrea

Figured out a work around for the noise component of the refraction effect. I guess volume textures make it easier, but aren't vital.





Re: XNA Game Studio Express Volume textures, HLSL and re-creating rendermonkey effects

Kyle0654

I certainly hope Volume textures work, because I've been using them successfully for months on both Windows and Xbox using XNA. Perhaps you could describe where you've been having problems with Volume textures If you want to create a noise texture, it's pretty easy to do that at program startup. I'm not sure if loading pre-created Volume textures is unsupported, though I'd be very disappointed if it weren't, as I was planning on converting some data to Volume textures to speed up loading time. You shouldn't have any problems creating Volume textures by yourself though (aside from having to specify your own Vertex format for 3D texture coordinates).




Re: XNA Game Studio Express Volume textures, HLSL and re-creating rendermonkey effects

NickMcCrea

What I meant was that the content pipeline does not support volume texture importing/processing. There's some forum posts about it, if you search the XNA framework forum for 'volume texture'.

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1032753&SiteID=1

And the compiler threw a wobbler when I tried to import a volume texture prior to me making this thread.





Re: XNA Game Studio Express Volume textures, HLSL and re-creating rendermonkey effects

Thomas Aylesworth

Hey, Nick, would you mind posting your solution for the rest of us who are trying to learn HLSL BTW, going through the RenderMonkey exercises in XNA is a great idea... I'm going to start on that now myself!



Re: XNA Game Studio Express Volume textures, HLSL and re-creating rendermonkey effects

NickMcCrea

Hi Thomas, to clarify, I didn't find a workaround for the lack of volume texture importer, rather I just slightly changed the pixel shader so that it didn't require a volume texture to perform the 'noise'. I misunderstood what the pixel shader was actually doing before I posted, afterwards I realised the volume texture isn't strictly necessary.

It's probably too generous to call it a solution, it's more of a hack. It achieves the refraction of the original shader, and also the 'distortion' that looks like refraction of a rippling water surface, but the look is slightly different. It's practically identical, I switch textures (so using a 2D texture rather than the volume texture), switch around the noiseCoord values, so that noise is being added to the x coord, rather than z:

noiseCoord.x = texCoord.z + 0.2 * time_0_X + noisy;
noiseCoord.y = texCoord.y * 2;
noiseCoord.z = 0.1 * time_0_X;

and then tweak a few values to get rid of the 'striation'.

Trying to recreate the rendermonkey shaders has been invaluable. Simplest is the vertex lighting shader in the Illumination category. Then I tried per-pixel. Then some of the other single-pass shaders, fabric, glitter etc. The water refraction was the latest I've tried - it doubles nicely as a glass/ice shader if you strip out the time-based noise, too...

Once you figure out rendermonkey, recreating in XNA is pretty simple.






Re: XNA Game Studio Express Volume textures, HLSL and re-creating rendermonkey effects

Thomas Aylesworth

Gotcha. Thanks for the info.



Re: XNA Game Studio Express Volume textures, HLSL and re-creating rendermonkey effects

Shawn Hargreaves - MSFT

Lack of content pipeline support for volume textures is certainly something we're aware of, it just didn't make it in time for the first version.

At the moment you can use volume textures just fine at runtime, and on Windows you can use Texture3D.FromFile to read .DDS files into them, but on Xbox they are a bit of a pain to author. Probably the easiest way is to have a separate 2D texture for each slice of the volume, then at runtime create a new Texture3D and use a bunch of GetData/SetData calls to copy information across from each individual 2D image.

Not very pretty. We'll have a proper volume texture importer for the next version.