Jump to content

  • Log In with Google      Sign In   
  • Create Account

Telanor

Member Since 01 Sep 2011
Offline Last Active Dec 23 2014 11:16 AM

#5071009 Having problems getting soft particles to work

Posted by Telanor on 18 June 2013 - 08:35 PM

Sorry for not replying sooner, somehow I didn't get a notification email. I'm using the same blending function from the nvidia sample:

float Contrast(float Input, float ContrastPower)
{
	//piecewise contrast function
	bool IsAboveHalf = Input > 0.5 ;
	float ToRaise = saturate(2*(IsAboveHalf ? 1-Input : Input));
	float Output = 0.5*pow(ToRaise, ContrastPower); 

	Output = IsAboveHalf ? 1-Output : Output;

	return Output;
}
The spoiler tag in the OP has the full shader code


#5068817 Having problems getting soft particles to work

Posted by Telanor on 11 June 2013 - 01:44 AM

Well, as far as I can tell, that is what I'm doing. The gbuffer value I'm reading in should be converted to projection-space and compared with the projection-space particle depth. I must have done something wrong though, because the particles look exactly the same as before; there's no fade-out near the intersection area.


#5068786 Having problems getting soft particles to work

Posted by Telanor on 10 June 2013 - 06:22 PM

I've been trying to implement soft particles as described in the nvidia paper. I'm having a problem with this part: "If we want to compare consistent depth values, the fetched value Zbuf needs to be transformed into projection space". I'm using log-depth, so I can't use the formula they're using. They also never explain what any of the variables in the equation are or why the comparison needs to be done in projection-space and not "Normalized device coordinate" space.

I know how to reconstruct a world-space position from a log-depth value from a previous topic, so I tried several different ways to get it to work for the soft particles.

For reference, this is the equation for the reconstruction:
float depthVal = DepthMap.Sample(depthSampler, texCoord).r; 
depthVal = (pow(0.001 * FarPlane + 1, depthVal) - 1) / 0.001;
depthVal /= (1 * FarPlane) / (FarPlane - 1); //The 1 is the near plane value

float2 invProjPos = mul(input.ScreenPosition.xy * depthVal, InverseProjection);
float4 position = mul(float4(invProjPos, -depthVal, 1), InverseView);

position /= position.w;
So I figured to get the projection-space value, the equation should be just the first 3 lines. Next, I figured the particle's Z value should be calculated like this (from the vertex shader):
float4 worldPosition = mul(float4(input.Position, 1), instanceTransform);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);

output.Position.z = log(0.001 * output.Position.z + 1) / log(0.001 * NearFar.y + 1) * output.Position.w;
output.Z = output.Position.z;
Now I know the value output to the depth buffer will be divided by the W normally, so I also tried changing the last line to:

output.Z = output.Position.z / output.Position.w;

In either case, the result is the same: no fading what-so-ever. The particles still have their hard edges. I'm not really sure what I'm doing wrong here and was hoping someone could point it out.

Full shader code:
Spoiler



#5065441 Need some tips on improving water shader

Posted by Telanor on 28 May 2013 - 01:02 AM

We're not using screen normals though, they're regular world space normals. The problem is coming from the lighting equation making it black on the side that's facing away from the light. Actually.... in the processing of writing this I had an idea. There's no reason I need to do the lighting equation using the normal after the normal-mapping is applied. I switched it to just use the flat plane's normal and now the black is gone. Thanks for the suggestions guys.


#5065397 Need some tips on improving water shader

Posted by Telanor on 27 May 2013 - 08:40 PM

Ah, so the streaking can't be fixed without actually making the plane 3D. I managed to figure out the specular issue. The backsides of waves being black is about the only issue left now.


#5063365 Need some tips on improving water shader

Posted by Telanor on 20 May 2013 - 07:00 PM

Ok, two more issues. The lighting equation is causing the backside of waves to turn black:

RuinValor 2013-05-20 20-44-29-97.png

Also, this is something that's been around for a while. One side of the wave (I'm guessing it's the back) is getting a strong reflection while the other side has a strong refraction. It's creating a kind of spotted/streak effect near the viewer where the water will be mostly transparent with spots of strong blue (from the sky) mixed in. This seems pretty unnatural to me. Any suggestions?

RuinValor-2013-05-20-20-45-20-21.jpg

And again with the water set to an orange color (in this case there are also some strong orange spots):

RuinValor 2013-05-20 20-58-48-77.png


#5063356 Need some tips on improving water shader

Posted by Telanor on 20 May 2013 - 06:11 PM

Ok, so a quick test of the lighting idea. I just multiplied the dot(normal, lightVector) with the final color. It works pretty well

RuinValor 2013-05-20 18-40-16-54.png

It's a little too dark too soon though.

unbird: I am using fresnel. The reflections weren't working right before though, I've fixed them now and the shallow angle fog seems to be a lot less of a problem.


#5063328 Need some tips on improving water shader

Posted by Telanor on 20 May 2013 - 04:29 PM

Changing the if statement to a saturate made the water turn entirely black at night. I'll give the lighting thing a try and see how that works out.


#5063322 Need some tips on improving water shader

Posted by Telanor on 20 May 2013 - 04:00 PM

I'm working on tweaking our water shader to get a nicer look out of it and there are a couple of issues I'm not sure how to solve. The main one is that the colorization, while nice during the day, makes the water look lit up at night and is very unnatural:

RuinValor 2013-05-19 20-57-37-99.png

All I'm doing is lerping between the sampled refraction color and a water color parameter. How can I make it so it isn't "creating light"?

Another issue I'm having is the specular. Works during the day, creates black spots at night. Running through the shader debugger, I found it was returning QNANs, but I can't understand why, I have an if-statement that should return 0 specular for when the dot product returns a negative:

float specular = dot(normalize(reflectionVector), -eyeVector);
float3 specColor = 0;

if(specular > 0)
{
	specular = pow(specular, SpecPower) * 5;
	
	if(specular > 0) //This doesnt help either
		specColor = normalize(SpecColor.rgb) * specular;
}

 
One last issue I'm working on is making the water color strength vary based on the depth of the water. I haven't been able to find any documentation online about this so I've just sort of been making something up and playing around with it to see what works well. What I've done so far is read the terrain depth buffer sampled straight along the view ray, subtracted the depth from the camera to the surface, and then used that in an exponential fog equation. It works pretty well but seems a bit strange when shallow water becomes very foggy when viewed at a shallow angle. Any advice for this?




#5054348 Projective Texturing

Posted by Telanor on 17 April 2013 - 05:43 PM

I found part of the problem was from me using the ViewProjection matrix from the wrong camera but now there seems to be an issue with the sampling coordinates for the projection depth map being wrong.

RuinValor 2013-04-17 19-33-24-01.png

The projector camera is positioned approximately where the cursor is and is looking straight downwards. Ive changed the code from before slightly
float4 decalPos = mul(position, DecalViewProjection);
decalPos /= decalPos.w;
decalPos.xy = float2(decalPos.x, -decalPos.y) / 2.0f + 0.5f;

float shadowDepth = ProjectorDepthMap.Sample(pointSampler, decalPos.xy);

return float4(shadowDepth.rrr, 1);



#5054109 Projective Texturing

Posted by Telanor on 17 April 2013 - 12:36 AM

That's what I figured but I wasn't able to get it to work. It just considers everything to be out of the shadow.
float4 position = //bunch of code to reconstruct world space position from log depth

float4 decalPos = mul(position, DecalViewProjection);

float shadowDepth = ProjectorDepthMap.Sample(pointSampler, decalTexCoord.xy);

if(shadowDepth < decalPos.z / decalPos.w)
	discard;



#5054097 Projective Texturing

Posted by Telanor on 16 April 2013 - 11:20 PM

I'm trying to implement projective texturing but I'm having some trouble getting it to a usable state. Right now it works but it projects to infinity (or more specifically, to the far plane). I can't just pull back the far plane because it could result in the texture being cut off on steep surfaces, and wouldn't solve the problem of projecting through surfaces. I've tried to mimic a sort of spotlight shadow technique but wasn't able to get that to work since there are pretty much no tutorials on shadows for deferred shading pipelines. So, my question: How do you get a projective texture to stop at the first surface it hits?


Edit: I forgot to add tags. I'm using DX11 & sharpdx


#5050510 Collida Model Loading + Bones + Control Rigs = Fail?

Posted by Telanor on 05 April 2013 - 11:46 PM

Turns out we had to bake animations and ignore any bones that didn't have animations


#5041404 Problems with camera looking up

Posted by Telanor on 09 March 2013 - 10:49 PM

I'm trying to calculate a view/projection/bounding frustum for the 6 directions of a point light and I'm having trouble with the views pointing along the Y axis. Our game uses a right-handed, Y-up system. For the other 4 directions I create the LookAt matrix using (0, 1, 0) as the up vector. Obviously that doesn't work when looking along the Y axis so for those I use an up vector of (-1, 0, 0) for -Y and (1, 0, 0) for +Y. The view matrix seems to come out correctly (and the projection matrix always stays the same), but the bounding frustum is definitely wrong.

This is the code I'm using:
camera.Projection = Matrix.PerspectiveFovRH((float)Math.PI / 2, ShadowMapSize / (float)ShadowMapSize, 1, 5);

for(var i = 0; i < 6; i++)
{
	var renderTargetView = shadowMap.GetRenderTargetView((TextureCubeFace)i);
	var up = DetermineLightUp((TextureCubeFace) i);
	var forward = DirectionToVector((TextureCubeFace) i);

	camera.View = Matrix.LookAtRH(Position, Position + forward, up);
	camera.BoundingFrustum = new BoundingFrustum(camera.View * camera.Projection);
}

private static Vector3 DirectionToVector(TextureCubeFace direction)
{
	switch (direction)
	{
		case TextureCubeFace.NegativeX:
			return -Vector3.UnitX;
		case TextureCubeFace.NegativeY:
			return -Vector3.UnitY;
		case TextureCubeFace.NegativeZ:
			return -Vector3.UnitZ;
		case TextureCubeFace.PositiveX:
			return Vector3.UnitX;
		case TextureCubeFace.PositiveY:
			return Vector3.UnitY;
		case TextureCubeFace.PositiveZ:
			return Vector3.UnitZ;
		default:
			throw new ArgumentOutOfRangeException("direction");
	}
}

private static Vector3 DetermineLightUp(TextureCubeFace direction)
{
	switch (direction)
	{
		case TextureCubeFace.NegativeY:
			return -Vector3.UnitX;
		case TextureCubeFace.PositiveY:
			return Vector3.UnitX;
		default:
			return Vector3.UnitY;
	}
}
I can post some example output if it'll help.


#5038349 Help me to make work D2D with D3D11

Posted by Telanor on 02 March 2013 - 03:57 AM

See here for instructions: http://blog.rthand.com/post/2010/10/25/Capture-DirectX-1011-debug-output-to-Visual-Studio.aspx

I think you need to add the application to the list before D3D11_CREATE_DEVICE_DEBUG has any effect




PARTNERS