Fix shadow again
This commit is contained in:
@@ -101,8 +101,6 @@ float ShadowCalculation(float4 shadowCoord, float3 normal) {
|
|||||||
|
|
||||||
shadow /= 9.0f;
|
shadow /= 9.0f;
|
||||||
|
|
||||||
// float shadowDepth = gShadowMap.Sample(gShadowSampler2, UVCoords.xy).r;
|
|
||||||
|
|
||||||
|
|
||||||
if(projCoord.z > 1.0)
|
if(projCoord.z > 1.0)
|
||||||
shadow = 0.0;
|
shadow = 0.0;
|
||||||
@@ -110,15 +108,38 @@ float ShadowCalculation(float4 shadowCoord, float3 normal) {
|
|||||||
return shadow;
|
return shadow;
|
||||||
}
|
}
|
||||||
// Pixel shader
|
// Pixel shader
|
||||||
|
// float4 PS(VS_OUTPUT input) : SV_TARGET {
|
||||||
|
// float shadowFactor = ShadowCalculation(input.ShadowCoord, input.Normal);
|
||||||
|
//
|
||||||
|
// float3 diffuseColor = gDiffuseMap.Sample(gSampleState, input.TexCoord).rgb;
|
||||||
|
//
|
||||||
|
// float3 finalColor = diffuseColor * (1 - shadowFactor);
|
||||||
|
// finalColor += gAmbient;
|
||||||
|
//
|
||||||
|
// return float4(finalColor, 1.0f);
|
||||||
|
// }
|
||||||
|
|
||||||
float4 PS(VS_OUTPUT input) : SV_TARGET {
|
float4 PS(VS_OUTPUT input) : SV_TARGET {
|
||||||
float shadowFactor = ShadowCalculation(input.ShadowCoord, input.Normal);
|
float3 color = gDiffuseMap.Sample(gSampleState, input.TexCoord).rgb;
|
||||||
|
float3 normal = normalize(input.Normal);
|
||||||
|
|
||||||
float3 diffuseColor = gDiffuseMap.Sample(gSampleState, input.TexCoord).rgb;
|
float3 lightDir = normalize(-gLightDirection);
|
||||||
|
float3 viewDir = normalize(gCameraPosition - input.WorldPosition.xyz);
|
||||||
|
|
||||||
float3 finalColor = diffuseColor * (1 - shadowFactor);
|
float3 ambient = gAmbient;
|
||||||
finalColor += gAmbient;
|
|
||||||
|
|
||||||
return float4(finalColor, 1.0f);
|
float diff = max(dot(normal, lightDir), 0.0);
|
||||||
|
|
||||||
|
float3 diffuse = gLightColor * diff * color;
|
||||||
|
|
||||||
|
float3 reflectDir = reflect(-lightDir, normal);
|
||||||
|
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
|
||||||
|
float3 specular = gLightColor * spec;
|
||||||
|
|
||||||
|
float shadow = ShadowCalculation(input.ShadowCoord, normal);
|
||||||
|
float3 lighting = (ambient + (1.0 - shadow) * (diffuse + specular)) * color;
|
||||||
|
|
||||||
|
return float4(lighting, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DepthStencilState
|
// DepthStencilState
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ ID3DX11Effect *BaseEffect::LoadEffect(ID3D11Device *devicePtr, const std::wstrin
|
|||||||
ss << errorsPtr[i];
|
ss << errorsPtr[i];
|
||||||
OutputDebugStringW(ss.str().c_str());
|
OutputDebugStringW(ss.str().c_str());
|
||||||
|
|
||||||
|
|
||||||
errorBlobPtr->Release();
|
errorBlobPtr->Release();
|
||||||
errorBlobPtr = nullptr;
|
errorBlobPtr = nullptr;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -72,7 +73,6 @@ void BaseEffect::SetWorldViewProjMatrix(const dae::Matrix &matrix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseEffect::NextSamplingState() {
|
void BaseEffect::NextSamplingState() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEffect::SetCameraPos(const dae::Vector3 &vector3) const {
|
void BaseEffect::SetCameraPos(const dae::Vector3 &vector3) const {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "Effects/Effect.h"
|
#include "Effects/Effect.h"
|
||||||
#include "Effects/FireEffect.h"
|
|
||||||
#include "HitTest.h"
|
#include "HitTest.h"
|
||||||
#include "Scenes/MainScene.h"
|
#include "Scenes/MainScene.h"
|
||||||
#include "Scenes/DioramaScene.h"
|
#include "Scenes/DioramaScene.h"
|
||||||
|
|||||||
@@ -34,9 +34,26 @@ void ShadowTestScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *D
|
|||||||
auto otherEffect = new ShadowDiffuse(DevicePtr, L"resources/SuperSimpleDiffuse.fx");
|
auto otherEffect = new ShadowDiffuse(DevicePtr, L"resources/SuperSimpleDiffuse.fx");
|
||||||
|
|
||||||
auto shadowMesh = new ShadowMesh(DevicePtr, vertices, indices, material, shadowEffect, otherEffect);
|
auto shadowMesh = new ShadowMesh(DevicePtr, vertices, indices, material, shadowEffect, otherEffect);
|
||||||
|
|
||||||
|
|
||||||
|
if(!Utils::ParseOBJNew("resources/tuktuk.obj", vertices, indices, true)){
|
||||||
|
assert(true && "Model failed to load");
|
||||||
|
}
|
||||||
|
|
||||||
|
material = std::make_shared<Material>();
|
||||||
|
material->diffuseTexturePtr = Texture::LoadFromFile("resources/tuktuk.png", DevicePtr);
|
||||||
|
|
||||||
|
shadowEffect = new ShadowEffect(DevicePtr, L"resources/shadowEffect.fx");
|
||||||
|
otherEffect = new ShadowDiffuse(DevicePtr, L"resources/SuperSimpleDiffuse.fx");
|
||||||
|
|
||||||
|
auto shadowMesh2 = new ShadowMesh(DevicePtr, vertices, indices, material, shadowEffect, otherEffect);
|
||||||
|
|
||||||
|
shadowMesh2->SetWorldMatrix(Matrix::CreateTranslation(Vector3(0, -5, 40)));
|
||||||
|
m_tuktukMesh = shadowMesh2;
|
||||||
|
m_shadowMeshes.push_back(shadowMesh2);
|
||||||
//
|
//
|
||||||
|
|
||||||
// std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
// std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
|
||||||
// Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
// Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
|
||||||
// for (const auto &mesh: materialMeshes) {
|
// for (const auto &mesh: materialMeshes) {
|
||||||
// if (mesh->vertices.size() > 0) {
|
// if (mesh->vertices.size() > 0) {
|
||||||
@@ -70,14 +87,20 @@ void ShadowTestScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *D
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ShadowTestScene::Update() {
|
void ShadowTestScene::Update() {
|
||||||
|
|
||||||
// m_Light.SetTarget(lightTarget);
|
// m_Light.SetTarget(lightTarget);
|
||||||
Vector3 pos = m_Light.GetPosition();
|
Vector3 pos = m_Light.GetPosition();
|
||||||
pos.y = sin(SDL_GetTicks() / 1000.f) * 10.f + 10.f;
|
pos.y = sin(SDL_GetTicks() / 1000.f) * 10.f + 10.f;
|
||||||
m_Light.SetPosition(pos);
|
m_Light.SetPosition(pos);
|
||||||
|
|
||||||
|
|
||||||
m_Light.Update();
|
m_Light.Update();
|
||||||
|
|
||||||
|
|
||||||
|
//rotate tutkuk
|
||||||
|
|
||||||
|
Matrix newOne;
|
||||||
|
newOne *= Matrix::CreateRotationY(0.001f * SDL_GetTicks());
|
||||||
|
newOne *= Matrix::CreateTranslation(Vector3(20, -5, 40));
|
||||||
|
m_tuktukMesh->SetWorldMatrix(newOne);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShadowTestScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
void ShadowTestScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr,
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ private:
|
|||||||
|
|
||||||
float angle = 0.0f;
|
float angle = 0.0f;
|
||||||
|
|
||||||
|
ShadowMesh* m_tuktukMesh;
|
||||||
|
|
||||||
void RenderShadowMapToScreen(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr);
|
void RenderShadowMapToScreen(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView *renderTargetViewPtr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ void CheckController(Renderer* pRenderer, bool& printFPS){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *args[]) {
|
int main(int argc, char *args[]) {
|
||||||
//Unreferenced parameters
|
//Unreferenced parameters
|
||||||
(void) argc;
|
(void) argc;
|
||||||
@@ -129,9 +130,13 @@ int main(int argc, char *args[]) {
|
|||||||
|
|
||||||
//Create window + surfaces
|
//Create window + surfaces
|
||||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
||||||
|
//
|
||||||
|
// const uint32_t width = 640;
|
||||||
|
// const uint32_t height = 480;
|
||||||
|
|
||||||
const uint32_t width = 640;
|
|
||||||
const uint32_t height = 480;
|
const uint32_t width = 900;
|
||||||
|
const uint32_t height = 600;
|
||||||
|
|
||||||
RenderSettings::GetInstance().setHeight(height);
|
RenderSettings::GetInstance().setHeight(height);
|
||||||
RenderSettings::GetInstance().setWidth(width);
|
RenderSettings::GetInstance().setWidth(width);
|
||||||
|
|||||||
Reference in New Issue
Block a user