This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vec3 center = pos + CalcGerstnerWaveOffset(immutableCb, pos, terrainFrameCB.g_time); | |
Vec3 offsetXZ = pos + Vec3(1, 0, 1) + CalcGerstnerWaveOffset(immutableCb, pos + Vec3(1, 0, 1), terrainFrameCB.g_time); | |
Vec3 offsetNegX = pos + Vec3(-1, 0, 0) + CalcGerstnerWaveOffset(immutableCb, pos + Vec3(-1, 0, 0), terrainFrameCB.g_time); | |
Vec3 offsetNegZ = pos + Vec3(0, 0, -1) + CalcGerstnerWaveOffset(immutableCb, pos + Vec3(0, 0, -1), terrainFrameCB.g_time); | |
Vec3 normal = normalize(cross(offsetNegZ - offsetXZ, offsetNegX - offsetXZ)); | |
Vec3 rotAxis = normalize(cross(normal, Vec3(0, 1, 0))); | |
float rotRad = acos(dot(normal, Vec3(0, 1, 0))); | |
cube.Draw(MeshXAnimResult(), scale(5, 5, 5) * q2m(Quat(rotAxis, -rotRad)) * translate(center.x, center.y, center.z)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Wave | |
{ | |
Vec2 dir; | |
float amplitude; | |
float waveLength; | |
}; | |
struct ImmutableCB | |
{ | |
float waveSteepness; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float3 gerstnerWaveN = CalcGerstnerWaveNormal(vertexPosition + ofsByGerstnerWave); | |
float3 gerstnerWaveB = CalcGerstnerWaveBinormal(vertexPosition + ofsByGerstnerWave); | |
float3 gerstnerWaveT = CalcGerstnerWaveTangent(vertexPosition + ofsByGerstnerWave); | |
float3x3 rotator; | |
rotator[0] = gerstnerWaveB; | |
rotator[1] = gerstnerWaveN; | |
rotator[2] = gerstnerWaveT; | |
output.normal = mul(water_normal.xyz, rotator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float3 CalcGerstnerWaveNormal(float3 P) | |
{ | |
float3 normal = float3(0, 1, 0); | |
[unroll] | |
for (int i = 0; i < numWaves; i++) | |
{ | |
Wave wave = waves[i]; | |
float wi = 2 / wave.waveLength; | |
float WA = wi * wave.amplitude; | |
float phi = speed * wi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float3 ofsByGerstnerWave = CalcGerstnerWaveOffset(vertexPosition); | |
float3 dx = float3(0.01, 0, 0) + CalcGerstnerWaveOffset(vertexPosition + float3(0.01, 0, 0)); | |
float3 dz = float3(0, 0, 0.01) + CalcGerstnerWaveOffset(vertexPosition + float3(0, 0, 0.01)); | |
float3 N = normalize(cross(dz - ofsByGerstnerWave, dx - ofsByGerstnerWave)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Wave | |
{ | |
Vec2 dir; | |
float amplitude; | |
float waveLength; | |
}; | |
struct ImmutableCB | |
{ | |
Wave waves[100]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Wave | |
{ | |
float2 dir; | |
float amplitude; | |
float waveLength; | |
}; | |
cbuffer cb2 : register(b2) | |
{ | |
Wave waves[100]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static float3 lightPosition = { 100, 0, 1000 }; // 'static' needed. not 'const'! | |
float3 CalcLightDir(float3 myPosition) | |
{ | |
return normalize(lightPosition - myPosition); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float3 lightPosition = { 100, 0, 1000 }; // This makes an implicit constant buffer, but the light position never assigned! | |
float3 CalcLightDir(float3 myPosition) | |
{ | |
return normalize(lightPosition - myPosition); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ComPtr<ID3D12DescriptorHeap> rtvHeap, dsvHeap; | |
ID3D12GraphicsCommandList* commandList; | |
ID3D12Device* device; | |
void CreateHeaps() | |
{ | |
D3D12_DESCRIPTOR_HEAP_DESC rtvDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1 }; | |
device->CreateDescriptorHeap(&rtvDesc, IID_PPV_ARGS(&rtvHeap)); | |
D3D12_DESCRIPTOR_HEAP_DESC dsvDesc = { D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 1 }; | |
device->CreateDescriptorHeap(&dsvDesc, IID_PPV_ARGS(&rtvHeap)); |
NewerOlder