• Create Account

# mgoss

Member Since 28 Apr 2012
Offline Last Active Oct 26 2014 03:42 PM

### Calculating Vertex Normals

06 June 2013 - 11:35 AM

```foreach( Vertex v )
{
Vector3 normal = Vector3.Zero;
foreach (Face f adjacent to v )
{
normal += f.GetNormal();
}
normal.Normalize();
}
```

I found this algorithm. However, I'm not sure how to figure if a face is adjacent to a vertex. The reason I'm doing this is because I'm generating terrain and it's very blocky. I was told using vertex normals for lighting will smooth it out.

### DX11 Depth RT issue

05 August 2012 - 04:22 AM

I'm having issues writing a depth RT correctly.
```float4x4 ViewProjection;
{
float4 Position   : SV_POSITION0;
float2 Depth   : TEXCOORD0;
};
{
float4 position = mul(Position, ViewProjection);
output.Position = position;
output.Depth = position.zw;
return output;
}
{
float depth = input.Depth.x / input.Depth.y;
return float4(depth, depth * depth, 0, 0);
}
technique11 Depth
{
pass p0
{
}
}
```

### Reconstruct position from log depth

13 July 2012 - 01:15 AM

Here how I'm applying the logarithmic depth in the vertex shader.
output.Position.z = log(output.Position.z / 0.001) / log(FarPlane / 0.001) * output.Position.w; //log(z/zn)/log(zf/zn)

Reconstructing in pixel shader. Not sure if i'm doing this correctly.

float depthVal = DepthMap.Sample(depthSampler, texCoord).r;

//Compute screen-space position
float4 position = float4(input.ScreenPosition.xy, depthVal, 1.0f);
position.z = exp(depthVal * log(FarPlane / 0.001)) * 0.001; //(exp(z*log(zf/zn))*zn : z = depth value

//transform to world space
position = mul(position, InvertViewProjection);
position /= position.w;

### NORMALS wrong place in Collada?

10 July 2012 - 01:37 PM

Sometimes when Maya exports models, it exports them the normals in a different location.

Sometimes it puts the normals under the <vertices>

<vertices id="objgoblin_1-VERTEX">
<input semantic="POSITION" source="#objgoblin_1-POSITION"/>
<input semantic="NORMAL" source="#objgoblin_1-Normal0"/>
</vertices>
<triangles count="7820" material="_3_FBXASC045_Default">
<input semantic="VERTEX" offset="0" source="#objgoblin_1-VERTEX"/>
<input semantic="TEXCOORD" offset="1" set="0" source="#objgoblin_1-UV0"/>
</triangles>

When typically it exports them like this

<vertices id="pCylinder1-VERTEX">
<input semantic="POSITION" source="#pCylinder1-POSITION"/>
</vertices>
<triangles count="120" material="lambert2">
<input semantic="VERTEX" offset="0" source="#pCylinder1-VERTEX"/>
<input semantic="NORMAL" offset="1" source="#pCylinder1-Normal0"/>
</triangles>

What's the difference and why does it export them at two different locations? I would prefer it to always have it in the triangles node. Because I need the offset.