Working on shadow mapping
This commit is contained in:
parent
a35340a930
commit
a355a563f8
|
@ -70,15 +70,19 @@ void main() {
|
||||||
vec3 specular = light0SpecularColor * specularFactor;
|
vec3 specular = light0SpecularColor * specularFactor;
|
||||||
|
|
||||||
// Compute shadow factor
|
// Compute shadow factor
|
||||||
float shadowBias = 0.005;
|
float bias = 0.00001;
|
||||||
|
float shadowBias = -0.000;
|
||||||
vec4 shadowMapUV = shadowMapCoords;
|
vec4 shadowMapUV = shadowMapCoords;
|
||||||
shadowMapUV.z -= shadowBias;
|
shadowMapUV.z -= shadowBias;
|
||||||
vec4 shadowMapCoordsOverW = shadowMapUV / shadowMapUV.w ;
|
vec4 shadowMapCoordsOverW = shadowMapUV / shadowMapUV.w ;
|
||||||
float distanceInShadowMap = texture(shadowMapSampler, shadowMapCoordsOverW.xy).r;
|
float distanceInShadowMap = texture(shadowMapSampler, shadowMapCoordsOverW.xy).r + bias;
|
||||||
float shadow = 0.0;
|
float shadow = 0.0;
|
||||||
if (shadowMapCoords.w > 0) {
|
if (shadowMapCoords.w > 0) {
|
||||||
shadow = distanceInShadowMap < shadowMapCoordsOverW.z ? 0.5 : 1.0;
|
shadow = distanceInShadowMap < shadowMapCoordsOverW.z ? 0.5 : 1.0;
|
||||||
}
|
}
|
||||||
|
if (abs(dot(N, L0)) < 0.01) {
|
||||||
|
shadow = 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute the final color
|
// Compute the final color
|
||||||
color = vec4(ambient + shadow * vertexColor.rgb, 1.0);
|
color = vec4(ambient + shadow * vertexColor.rgb, 1.0);
|
||||||
|
|
|
@ -135,11 +135,39 @@ void Gui::displayLeftPane() {
|
||||||
app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH,
|
app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH,
|
||||||
app.mWindowToFramebufferRatio.y * LEFT_PANE_HEADER_HEIGHT, &scrollarea);
|
app.mWindowToFramebufferRatio.y * LEFT_PANE_HEADER_HEIGHT, &scrollarea);
|
||||||
|
|
||||||
|
// ------ Header ----- //
|
||||||
|
|
||||||
|
imguiHorizontalSpace(10);
|
||||||
|
imguiVerticalSpace(20);
|
||||||
|
imguiStartLine();
|
||||||
|
|
||||||
|
const int button_width = 150;
|
||||||
|
|
||||||
|
// Play/Pause
|
||||||
|
if (imguiButton(app.mTimer.isRunning() ? "Pause" : "Play", true, button_width)) {
|
||||||
|
app.togglePlayPauseSimulation();
|
||||||
|
}
|
||||||
|
imguiHorizontalSpace(5);
|
||||||
|
|
||||||
|
// Step
|
||||||
|
if (imguiButton("Step", !app.mTimer.isRunning(), button_width)) {
|
||||||
|
app.toggleTakeSinglePhysicsStep();
|
||||||
|
}
|
||||||
|
imguiHorizontalSpace(5);
|
||||||
|
|
||||||
|
// Restart
|
||||||
|
if (imguiButton("Restart", true, button_width)) {
|
||||||
|
app.restartSimulation();
|
||||||
|
}
|
||||||
|
|
||||||
|
imguiEndLine();
|
||||||
|
|
||||||
imguiSeparatorLine();
|
imguiSeparatorLine();
|
||||||
imguiVerticalSpace(5);
|
imguiVerticalSpace(5);
|
||||||
imguiStartLine();
|
imguiStartLine();
|
||||||
|
|
||||||
// ----- Left Pane Header ----- //
|
// ----- Left Pane Tabs ----- //
|
||||||
|
|
||||||
int widthButton = app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH / 4.3;
|
int widthButton = app.mWindowToFramebufferRatio.x * LEFT_PANE_WIDTH / 4.3;
|
||||||
if (imguiButton("Scenes", true, widthButton)) {
|
if (imguiButton("Scenes", true, widthButton)) {
|
||||||
mLeftPane = SCENES;
|
mLeftPane = SCENES;
|
||||||
|
@ -323,7 +351,7 @@ void Gui::render() {
|
||||||
- app.mWindowToFramebufferRatio.y * mScrollY);
|
- app.mWindowToFramebufferRatio.y * mScrollY);
|
||||||
resetScroll();
|
resetScroll();
|
||||||
|
|
||||||
displayHeader();
|
//displayHeader();
|
||||||
displayLeftPane();
|
displayLeftPane();
|
||||||
|
|
||||||
imguiEndFrame();
|
imguiEndFrame();
|
||||||
|
|
|
@ -44,7 +44,7 @@ SceneDemo::SceneDemo(const std::string& name, float sceneRadius) : Scene(name),
|
||||||
mShadowMapLightCamera.rotateLocal(Vector3(1, 0, 0), -PI / 4.0f);
|
mShadowMapLightCamera.rotateLocal(Vector3(1, 0, 0), -PI / 4.0f);
|
||||||
mShadowMapLightCamera.setDimensions(SHADOWMAP_WIDTH, SHADOWMAP_HEIGHT);
|
mShadowMapLightCamera.setDimensions(SHADOWMAP_WIDTH, SHADOWMAP_HEIGHT);
|
||||||
mShadowMapLightCamera.setFieldOfView(70.0f);
|
mShadowMapLightCamera.setFieldOfView(70.0f);
|
||||||
mShadowMapLightCamera.setSceneRadius(200);
|
mShadowMapLightCamera.setSceneRadius(100);
|
||||||
//mShadowMapLightCamera.setZoom(1.0);
|
//mShadowMapLightCamera.setZoom(1.0);
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,6 +76,9 @@ void SceneDemo::render() {
|
||||||
|
|
||||||
// ---------- Render the scene to generate the shadow map (first pass) ----------- //
|
// ---------- Render the scene to generate the shadow map (first pass) ----------- //
|
||||||
|
|
||||||
|
//glEnable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
//glPolygonOffset(8.0, 4.0);
|
||||||
|
|
||||||
// Culling switching, rendering only backface, this is done to avoid self-shadowing
|
// Culling switching, rendering only backface, this is done to avoid self-shadowing
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
|
@ -109,6 +112,8 @@ void SceneDemo::render() {
|
||||||
|
|
||||||
mFBOShadowMap.unbind();
|
mFBOShadowMap.unbind();
|
||||||
|
|
||||||
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
|
||||||
|
|
||||||
// ---------- Render the scene for final rendering (second pass) ----------- //
|
// ---------- Render the scene for final rendering (second pass) ----------- //
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user