Jump to content

  • Log In with Google      Sign In   
  • Create Account


zonozz

Member Since 16 Dec 2012
Offline Last Active Jun 24 2013 12:36 PM
-----

Posts I've Made

In Topic: Question About Fluid simulation

24 June 2013 - 12:39 PM

Rendering and shading fluids is definitely tricky, but if course it very much depends on how you computed them in the first place.

If you have a eulerian grid which you used to compute motion by diffusing and advecting velocities / temperatures / densities / colours, you can pretty easily ray trace through the volume and get some decent results, depending on the resolution of your grid.

 

If you went down the sph / mass particles way, I find it trickier. Depending on what kind of fluid you are trying to render, you could render multiple times, to get surface depth and thickness, and then composite together. 

Or you could try sorting them and alpha blending them. Of you could try bucketing them into screen tiles/cluters and evaluating each block to reconstruct your surface. Marching cubes could be an option?

You mean that different fluids, like difference between ocean and a cup of water, will be simulated in different methods( I think maybe it's just a something detail in equation's item, is that right ?) ? I'm stopped at surface-reconstruction, that's very hard to me. I try to read a lot of opensource and thesis, then I can do next.


In Topic: Question About Fluid simulation

24 June 2013 - 12:32 PM

This is the guy responsible for the most gorgeous fluid effects in films:

http://physbam.stanford.edu/~fedkiw/

Also check out his lighthouse video:

http://www.youtube.com/watch?v=g2lsuk4rybY

Thank you, I already had saved his site


In Topic: Tangent Binormal Normal

13 June 2013 - 11:47 AM

Oh, guys, thank you all !

 

I think I've remind the reason about that, I read the old book just now, and the 1st chapter is about physical wave. There is information about tangent & binormal theory.

 

Book - GPU Gem 1 By nVIDIA


In Topic: About water refraction

25 April 2013 - 01:38 AM

Can anyone help me please ?

 

1. Why I need to calculate refraction & reflection vector ? Use reflection & refraction render texture for water plane will contribute some visual error ?

 

2. I debugged today, and another problem here, the whole water plane rocked when I turn my camera, I always feel that the surface of the water there is a delay. ( It means the water plane will dislocated with the bath. )


In Topic: About water refraction

24 April 2013 - 09:43 AM

It looks like your refraction vector is wrong, the reflection one looks correct. How are you calculating it? The statue should appear elongated and bent at the bottom, not broken (same for the pool edge refractions in the background). Basically, post some code, because without code we cannot do much more than say "it looks wrong".

 

OK,But I'll post HLSL's code, but I dont know Why I need reflection vector and refraction vector ? I already render the final effect (Combine reflection & refraction).

 

Here is my code in Vertex Shader & Pixel Shader :

/*
 * File name - Water.vs
 * Author - CuiXue
 * Updated date - 2013.4.21
 * Desc - 
 *
 */

 cbuffer MatrixBuffer
 {
	matrix world;
	matrix view;
	matrix proj;
 };

 cbuffer ReflectionBuffer
 {
	matrix reflectionMatrix;
 };

 cbuffer CameraBuffer
 {
	float3 cameraPosition;
	float padding;
 };

 struct VS_INPUT
 {
	float4 position : POSITION;
	float2 tex		: TEXCOORD0;
	float3 normal	: NORMAL;
	float3 tangent	: TANGENT;
	float3 binormal	: BINORMAL;
 };

 struct PS_INPUT
 {
	float4 position : SV_POSITION;
	float2 tex1		: TEXCOORD0;
	float2 tex2		: TEXCOORD4;
	float4 reflectionPos : TEXCOORD1;
	float4 refractionPos : TEXCOORD2;
	float3 viewDirection : TEXCOORD3;
	float3 normal	: NORMAL;
	float3 tangent		 : TANGENT;
	float3 binormal		 : BINORMAL;
 };

 PS_INPUT WaterVS(VS_INPUT input)
 {
	PS_INPUT output = (PS_INPUT)0;

	float4 worldPos;

	matrix reflectionProjWorld;
	matrix viewProjWorld;

	input.position.w = 1.0f;

	output.position = mul(input.position, world);
	output.position = mul(output.position, view);
	output.position = mul(output.position, proj);

	output.normal = mul(input.normal, (float3x3)world);
	output.normal = normalize(output.normal);

	output.tangent = mul(input.tangent, (float3x3)world);
	output.tangent = normalize(output.tangent);

	output.binormal = mul(input.binormal, (float3x3)world);
	output.binormal = normalize(output.binormal);

	reflectionProjWorld = mul(reflectionMatrix, proj);
	reflectionProjWorld = mul(world, reflectionProjWorld);
	output.reflectionPos = mul(input.position, reflectionProjWorld);

	viewProjWorld = mul(view, proj);
	viewProjWorld = mul(world, viewProjWorld);
	output.refractionPos = mul(input.position, viewProjWorld);

	worldPos = mul(input.position, world);
	output.viewDirection = cameraPosition.xyz - worldPos.xyz;
	output.viewDirection = normalize(output.viewDirection);

	output.tex1 = input.tex / 1.0f;
	output.tex2 = input.tex / 0.5f;

	return output;
 }

 

 

 

Pixel Shader :

/*
 * File name - Water.ps
 * Author - CuiXue
 * Updated date - 2013.4.21
 * Desc - 
 *
 */
 SamplerState samplerState;
 Texture2D reflectionTex;
 Texture2D refractionTex;
 Texture2D normalTex;

 cbuffer WaterBuffer
 {
	float reflection_refraction_scale;
	float water_translation;
	float2 padding;
 };

 cbuffer LightBuffer
 {
	float4 ambientColor;
	float4 diffuseColor;
	float3 direction;
	float specularPower;
	float4 specularColor;
 };

 struct PS_INPUT
 {
	float4 position : SV_POSITION;
	float2 tex1		: TEXCOORD0;
	float2 tex2		: TEXCOORD4;
	float4 reflectionPos : TEXCOORD1;
	float4 refractionPos : TEXCOORD2;
	float3 viewDirection : TEXCOORD3;
	float3 normal		 : NORMAL;
	float3 tangent		 : TANGENT;
	float3 binormal		 : BINORMAL;
 };

 float4 WaterPS(PS_INPUT input) : SV_TARGET
 {
	// Water params
	float fresnel;
	float specular;
	float r;
	float2 reflection_sample_coord;
	float2 refraction_sample_coord;
	float3 normal1;
	float3 normal2;
	float3 normal;
	float3 reflection;
	float3 heightView;
	float4 reflectionColor;
	float4 refractionColor;
	float4 refl_refr_lerpColor;
	float4 normalMap1;
	float4 normalMap2;
	float4 outputColor;

	float4 water_refl_color = float4( 0.7f, 0.9f, 0.7f, 1.0 );
	float4 water_refr_color = float4( 0.6f, 1.0f, 0.6f, 1.0 );

	input.tex1.y = input.tex1.y - water_translation;
	input.tex2.x = input.tex2.x + water_translation;

	heightView.x = input.viewDirection.y;
	heightView.y = input.viewDirection.y;
	heightView.z = input.viewDirection.y;

	reflection_sample_coord.x =  input.reflectionPos.x / input.reflectionPos.w / 2.0f + 0.5f;
	reflection_sample_coord.y = -input.reflectionPos.y / input.reflectionPos.w / 2.0f + 0.5f;

	refraction_sample_coord.x =  input.refractionPos.x / input.refractionPos.w / 2.0f + 0.5f;
	refraction_sample_coord.y = -input.refractionPos.y / input.refractionPos.w / 2.0f + 0.5f;
	
	// Sample normal map
	normalMap1 = normalTex.Sample(samplerState, input.tex1);
	normalMap2 = normalTex.Sample(samplerState, input.tex2);
	normal1 = (normalMap1.rgb * 2.0f) - 1.0f;
	normal2 = (normalMap2.rgb * 2.0f) - 1.0f;
	normal = normalize(normal1 + normal2);
	
	reflection_sample_coord = reflection_sample_coord + (normal.xy * reflection_refraction_scale);
	refraction_sample_coord = refraction_sample_coord + (normal.xy * reflection_refraction_scale);

	reflectionColor = reflectionTex.Sample(samplerState, reflection_sample_coord);
	refractionColor = refractionTex.Sample(samplerState, refraction_sample_coord);

	reflectionColor *= water_refl_color;
	refractionColor *= water_refr_color;

	// Calculate fresnel 
	r = pow((1.0 - 1.0 / 1.3), 2) / pow((1.0 + 1.0/1.3), 2);
	// r = pow((1.3f - 1.0f), 2) / pow((1.3f + 1.0f), 2);

	fresnel = max(0.0f, min(1.0f, r + (1.0f - r) * pow(1.0f - dot(normal, heightView), 5.0)));

	refl_refr_lerpColor = lerp(reflectionColor, refractionColor, fresnel);

	reflection = -reflect(normalize(direction), normal);

	specular = dot(normalize(reflection), normalize(input.viewDirection));

	if( specular > 0.0f )
	{
		specular = pow(specular, specularPower);

		refl_refr_lerpColor = saturate(refl_refr_lerpColor + specular * specularColor);
	}

	outputColor = refl_refr_lerpColor;

	return outputColor;
 }

 

 

I just sample the reflection texture & refraction texture. and combine these 2 pictures to water plane.


PARTNERS