Shadow map. Árnyékok kell: minden fényforrásra egy render target (Spotlight) egy közös depth buffer, aminek stimmel a mérete (EngineDeferred)

Slides:



Advertisements
Similar presentations
D3D10 techniques from Frostbite
Advertisements

Stupid OpenGL Shader Tricks
Arquitetura de GPU´s. a. Arquitetura de Hardware.
Far Cry and DirectX Carsten Wenzel Carsten Wenzel.
Advanced Virtual Texture Topics
OIT and Indirect Illumination using DX11 Linked Lists
Shader study Game and Windows applications can exist together on the desktop. When some event occurs, all video memory resources owned by the.
Deferred Shading Optimizations
Efficient High-Level Shader Development
Transzformációk, árnyalás, textúrák Szécsi László.
Render to texture Deferred shading Post-processing blur Szécsi László.
Részecskerendszerek, spriteok, plakátok, instancing Szécsi László.
PCF,VSM,LISPSM…. Kezdeti teendők Letöltés: OgreLabShadowMappingBase.zip Kicsomagol.sln futtat Include, lib és working dir beállítása Fordítás Futtatás.
Displacement mapping Szécsi László. Letöltés rock.obj rkd.jpg rbump.jpg rnormal.jpg.
Displacement mapping.
Plakátok, részecskerendszerek Szécsi László. copy-paste-rename gg009-Gui folder (sok zsiráf nem kell ide) vcxproj, filters átnevezés solution/add existing.
Environment mapping Szécsi László. copy-paste-rename gg007-Texture folder vcxproj, filters átnevezés solution/add existing project rename project working.
Árnyalás Szécsi László. giraffe.jpg letöltése SolutionDir/Media folderbe.
GPGPU labor VI. Rekurzív algoritmusok labirintus.
9.2. O THER NOTABLE AI A SPECTS / HLSL I NTRO Common board game AI approaches and Strategic AI.
Vertex Shader Tricks New Ways to Use the Vertex Shader to Improve Performance Bill Bilodeau Developer Technology Engineer, AMD.
Real-time Shading with Filtered Importance Sampling
Perspective aperture ygyg yryr n zgzg y s = y g (n/z g ) ysys y s = y r (n/z r ) zrzr.
Practical Implementation of High Dynamic Range Rendering Masaki Kawase BUNKASHA GAMES BUNKASHA PUBLISHING CO.,LTD
Low-level Thinking in High-level Shading Languages Emil Persson Head of Research, Avalanche Studios.
Advanced Real-Time Shader Techniques
Practical Clustered Shading
Johan Andersson Daniel Johansson Shadows & Decals: D3D10 techniques from Frostbite.
Frame Buffer Postprocessing Effects in DOUBLE-S.T.E.A.L (Wreckless)
Bump Mapping CSE 781 Roger Crawfis.
Week 8 - Friday.  What did we talk about last time?  Radiometry  Photometry  Colorimetry  Lighting with shader code  Ambient  Directional (diffuse.
Shooting in San Vanelona: the Visuals of EA's Skate.
GAM531 DPS931 – Week 11 Render State. The Render State Render State BuffersShadersSamplers Rasterizer State Blend State.
Pre-lighting in Resistance 2
Week 8 - Wednesday.  What did we talk about last time?  Textures  Volume textures  Cube maps  Texture caching and compression  Procedural texturing.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
void Direct3DBase::CreateDeviceResources() { D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
1 High Level Shader Language (HLSL) Chapter What is HLSL? The previous vertex and pixel shader programming is to use assembly language to write.
Week 3 - Wednesday.  What did we talk about last time?  Project 1  Graphics processing unit  Programmable shading.
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Illumination and Shading Lights Diffuse and Specular Illumination BasicEffect Setting and Animating.
Wilf LaLonde ©2012 Comp Shadows. Wilf LaLonde ©2012 Comp 4501 How Do I Draw a Pixel? Shadows volumes: Used in Doom (Expensive) From lights,
Week 3 - Friday.  What did we talk about last time?  Vertex shaders  Geometry shaders  Pixel shaders.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
Programming Concepts. Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture.
Geometric Objects and Transformations. Coordinate systems rial.html.
Overview [See Video file] Architecture Overview.
Week 3 - Monday.  What did we talk about last time?  Graphics rendering pipeline  Rasterizer Stage.
Computer graphics & visualization The programmable (D3D 10) Pipeline.
Real-Time High Quality Rendering CSE 291 [Winter 2015], Lecture 4 Brief Intro to Programmable Shaders
Shadow Mapping Chun-Fa Chang National Taiwan Normal University.
The Cg Runtime Cyril Zeller. Cg Pipeline Graphics programs are written in Cg and compiled to low-level assembly code... Cg Runtime API...
OpenGL Shading Language (GLSL)
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL Shading Language (GLSL)
2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE.
Motor III. Merev test animáció Szécsi László. Letöltés diák: //l08-engine3.ppt.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Gamebryo Shaders.
Shadows David Luebke University of Virginia. Shadows An important visual cue, traditionally hard to do in real-time rendering Outline: –Notation –Planar.
Advanced D3D10 Shader Authoring Presentation/Presenter Title Slide.
CgFX Sébastien Dominé, NVIDIA. Overview What is CgFX? CgFX runtime Production pipeline with CgFX CgFX Tools set Demo.
Postmortem: Deferred Shading in Tabula Rasa Rusty Koonce NCsoft September 15, 2008.
Designing a Modern GPU Interface
Reflective Shadow Mapping By: Mitchell Allen.
Week 8 - Wednesday CS361.
9.2. Other notable AI Aspects / HLSL Intro
null, true, and false are also reserved.
Introduction to Programmable Hardware
Texture and Shadow Mapping
Frame Buffer Applications
Presentation transcript:

Shadow map

Árnyékok kell: minden fényforrásra egy render target (Spotlight) egy közös depth buffer, aminek stimmel a mérete (EngineDeferred)

EngineDeferred.h LPDIRECT3DTEXTURE9 shadowMapDepthBufferTexture; LPDIRECT3DSURFACE9 shadowMapDepthBufferSurface; unsigned int shadowMapSize; void renderShadowMaps();

EngineDeferred::EngineDeferred shadowMapSize = 512;

EngineDeferred:: createDefaultResources device->CreateTexture( shadowMapSize, shadowMapSize, 1, D3DUSAGE_DEPTHSTENCIL, D3DFMT_D24S8, D3DPOOL_DEFAULT, &shadowMapDepthBufferTexture, NULL); shadowMapDepthBufferTexture->GetSurfaceLevel(0, &shadowMapDepthBufferSurface); SpotlightDirectory::iterator i = spotlightDirectory.begin(); while(i != spotlightDirectory.end()) { i->second->createShadowMap(device); i++; }

EngineDeferred:: releaseDefaultResources shadowMapDepthBufferTexture->Release(); shadowMapDepthBufferSurface->Release(); SpotlightDirectory::iterator i = spotlightDirectory.begin(); while(i != spotlightDirectory.end()) { i->second->releaseShadowMap(); i++; }

Spotlight.h LPDIRECT3DTEXTURE9 shadowMap; LPDIRECT3DSURFACE9 shadowSurface; unsigned int shadowMapSize; D3DXMATRIX lightViewProjMatrix; EntityCamera lightCamera; public: void createShadowMap(LPDIRECT3DDEVICE9 device); void releaseShadowMap(); void updateShadowMap(const RenderContext& context, NodeGroup* sceneRoot); LPDIRECT3DTEXTURE9 getShadowMap(); const D3DXMATRIX& getLightViewProjMatrix(); #include "EntityCamera.h"

Spotlight::Spotlight this->shadowMapSize = 512; D3DXMatrixIdentity( &lightViewProjMatrix);

Spotlight::createShadowMap void Spotlight::createShadowMap( LPDIRECT3DDEVICE9 device) { device->CreateTexture( shadowMapSize, shadowMapSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_R32F, D3DPOOL_DEFAULT, &shadowMap, NULL); shadowMap->GetSurfaceLevel( 0, &shadowSurface); }

Spotlight::releaseShadowMap void Spotlight::releaseShadowMap() { shadowMap->Release(); shadowSurface->Release(); }

Spotlight::updateShadowMap D3DXVECTOR3 worldPosition = getPosition(); D3DXVECTOR3 worldDirection = getDirection(); lightCamera = EntityCamera( NULL, worldPosition, worldPosition + worldDirection, D3DXVECTOR3(0, 0, 1), 1.55f, 1.0f, 0.1f, f); RenderContext lightContext( context.device, context.effect, &lightCamera, context.roleName);

folyt. context.device->SetRenderTarget(0, shadowSurface); context.device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(255, 0, 0, 0), 1.0f, 0); context.effect-> SetFloatArray("spotlight.position", (float*)&worldPosition, 3); // Spotlight többi tagja most nem kell sceneRoot->render(lightContext);

Spotlight const D3DXMATRIX& Spotlight::getLightViewProjMatrix(){ lightViewProjMatrix = lightCamera.getViewMatrix() * lightCamera.getProjMatrix(); return lightViewProjMatrix;} LPDIRECT3DTEXTURE9 Spotlight::getShadowMap(){ return shadowMap; }

EngineDeferred:: renderShadowMaps void EngineDeferred::renderShadowMaps(){ device->SetDepthStencilSurface( shadowMapDepthBufferSurface); SpotlightDirectory::iterator i = spotlightDirectory.begin(); while(i != spotlightDirectory.end()) { i->second->updateShadowMap( RenderContext(device, effect, NULL, L"shadow"), worldRoot); i++; } device->SetRenderTarget(0, displayColorBuffer); device->SetDepthStencilSurface( displayDepthStencilBuffer); } kell egy shadow Role

EngineDeferred:: createAutoShadedMesh shadedMesh->addRole( L"defer", new Role(materialBuffer, nSubmeshes, textureDirectory, device, "defer")); shadedMesh->addRole( L"shadow", new Role(materialBuffer, nSubmeshes, textureDirectory, device, "shadow"));

shadow map építő shader float4 psShadow(TrafoOutput input) : COLOR0 { return length(spotlight.position - input.worldPos); } technique shadow { pass P0 { VertexShader = compile vs_3_0 vsTrafo(); PixelShader = compile ps_3_0 psShadow(); } };

EngineDeferred::render blur dolgokat szedjük ki //device->SetRenderTarget(0, postProcSurface); //device->SetRenderTarget(1, NULL); //device->SetRenderTarget(0, deferredGeometrySurface); //effect->SetTexture("deferredGeometryMap", postProcTexture); //effect->SetTechnique("blurHorizontal"); //effect->Begin(&np, 0); //effect->BeginPass(0); //meshDirectory[L"quad"]->DrawSubset(0); //effect->EndPass(); //effect->End(); // //device->SetRenderTarget(0, displayColorBuffer); //effect->SetTexture("deferredGeometryMap", deferredGeometryTexture); //effect->SetTechnique("blurVertical"); //effect->Begin(&np, 0); //effect->BeginPass(0); //meshDirectory[L"quad"]->DrawSubset(0); //effect->EndPass(); //effect->End();

EngineDeferred::render device->BeginScene(); renderShadowMaps(); … // deferred buffer gyártás, setTexture effect->SetTechnique("deferredShadowed"); SpotlightDirectory::iterator i = spotlightDirectory.begin(); while(i != spotlightDirectory.end()) { Spotlight* spotlight = i->second; effect->SetFloatArray("spotlight.peakRadiance", (float*)&spotlight->getPeakRadiance(), 3);... // Spotlight többi tagja ugyanígy effect->SetTexture("shadowMap", spotlight->getShadowMap()); effect->SetMatrix("lightViewProjMatrix", &spotlight->getLightViewProjMatrix()); mezei deferred helyett

folyt. UINT np; effect->Begin(&np, 0); effect->BeginPass(0); meshDirectory[L"quad"] ->DrawSubset(0); effect->EndPass(); effect->End(); i++; }

.fx texture shadowMap; sampler2D shadowMapSampler =sampler_state{ texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; AddressU = Wrap; AddressV = Wrap; }; Spotlight spotlight; float4x4 lightViewProjMatrix;

.fx deferredShadowed technique deferredShadowed { pass P0 { ZEnable = false; ZWriteEnable = false; CullMode = None; AlphaBlendEnable = true; SrcBlend = One; DestBlend = One; BlendOp = Add; VertexShader = compile vs_3_0 vsQuad(); PixelShader = compile ps_3_0 psDeferredShadowed(); }};

psDeferredShadowed float4 psDeferredShadowed(QuadOutput input) : COLOR0 { float4 geometry = tex2D( deferredGeometrySampler, input.tex); float4 brdf = tex2D( deferredBrdfSampler, input.tex); float3 viewDir = normalize(input.worldPosMinusEye); float3 worldPos = eyePosition + viewDir * geometry.w; float4 shadowMapPos = mul(float4(worldPos, 1), lightViewProjMatrix); shadowMapPos /= shadowMapPos.w; float3 lightDiff = spotlight.position - worldPos; float lightDist = length(lightDiff); float2 lextex = shadowMapPos.xy * float2(0.5, -0.5) + float2(0.5, 0.5); float shadowDist = tex2D(shadowMapSampler, lextex); float visibility = lightDist < shadowDist + 0.5; return visibility * 0.5; };

lighting float4 psDeferredShadowed(QuadOutput input) : COLOR0 { float4 geometry = tex2D( deferredGeometrySampler, input.tex); float4 brdf = tex2D( deferredBrdfSampler, input.tex); float3 viewDir = normalize(input.worldPosMinusEye); float3 worldPos = eyePosition + viewDir * geometry.w; float4 shadowMapPos = mul(float4(worldPos, 1), lightViewProjMatrix); shadowMapPos /= shadowMapPos.w; float3 lightDiff = spotlight.position - worldPos; float lightDist = length(lightDiff); float3 lightDir = lightDiff / lightDist; float3 lighting = spotlight.peakRadiance * max(0, dot(geometry.xyz, lightDir)) * pow(max(0,dot(-lightDir, spotlight.direction)), spotlight.focus) / dot(lightDiff, lightDiff); float2 lextex = shadowMapPos.xy * float2(0.5, -0.5) + float2(0.5, 0.5); float shadowDist = tex2D(shadowMapSampler, lextex); float visibility = lightDist < shadowDist; return brdf * float4(lighting * visibility + float3(0.5, 0.5, 0.5), 1); };