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.

Slides:



Advertisements
Similar presentations
D3D10 techniques from Frostbite
Advertisements

Stupid OpenGL Shader Tricks
OIT and Indirect Illumination using DX11 Linked Lists
Efficient High-Level Shader Development
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)
Render to texture Deferred shading Post-processing blur Szécsi László.
Kezdeti teendők Letöltés: OgreBillboardParticles.zip Kicsomagol Futtat: OgreBillboardParticles.sln Include és library útvonalak beállítása Working directory.
Displacement mapping Szécsi László. Letöltés rock.obj rkd.jpg rbump.jpg rnormal.jpg.
Displacement mapping.
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 XIII. Folyadék szimuláció. Kezdeti teendők Tantárgy honlapja, Folyadék szimuláció A labor kiindulási alapjának letöltése (lab13_base.zip),
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
© Copyright Khronos Group, Page 1 COLLADA FX Update and FX Composer 2.0 Daniel Horowitz & Ignacio Castaño.
Introduction to Direct3D 12
Perspective aperture ygyg yryr n zgzg y s = y g (n/z g ) ysys y s = y r (n/z r ) zrzr.
Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Low-level Thinking in High-level Shading Languages Emil Persson Head of Research, Avalanche Studios.
Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
Johan Andersson Daniel Johansson Shadows & Decals: D3D10 techniques from Frostbite.
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.
GAM531 DPS931 – Week 11 Render State. The Render State Render State BuffersShadersSamplers Rasterizer State Blend State.
Filtering Approaches for Real-Time Anti-Aliasing
Particle System Design. The Challenge Particle systems vary so much But want some code reuse Option 1: parameterization Option 2: inheritance Option 3:
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Cg: C for Graphics Jon Moon Based on slides by Eugene Lee.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
2D graphics 3D graphics Segoe UI Fonts, text analysis, layout Image & video decoding GPGPU Too.
1 High Level Shader Language (HLSL) Chapter What is HLSL? The previous vertex and pixel shader programming is to use assembly language to write.
GAM532 DPS932 – Week 1 Rendering Pipeline and Shaders.
1 Texture Chapter 6. 2 What is Texture? Texture is a D3D interface that can map a partial of a picture to a 3D space by using Texture coordinates. The.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
Geometric Objects and Transformations. Coordinate systems rial.html.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Using Vertex Shader in DirectX 8.1 강 신 진
ACE Address Configuration Executive. Why ACE? ACE provides access to several address resolution protocols under a single API ACE is the only API available.
Overview [See Video file] Architecture Overview.
Matrices from HELL Paul Taylor Basic Required Matrices PROJECTION WORLD VIEW.
Computer graphics & visualization The programmable (D3D 10) Pipeline.
9.3. P ARTICLE S YSTEMS Development of a particle system.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
1 Dr. Scott Schaefer Programmable Shaders. 2/30 Graphics Cards Performance Nvidia Geforce 6800 GTX 1  6.4 billion pixels/sec Nvidia Geforce 7900 GTX.
AMD-SPL Runtime Programming Guide Jiawei. Outline.
1 Viewing & Projective Window Chapter 3. 2 D3D virtual viewpoint Definition: virtual viewpoint is like a camera that was positioned in some where and.
GAM532 DPS932 – Week 2 Vertex Shaders. The Shader Pipeline Vertex Processing Primitive Assembly / Processing Rasterization Fragment Process Pixel Output.
Useful Tools for Making Video Games Part II An overview of.
Copyright © 2002, Department of Systems and Computer Engineering, Carleton University CONTROL STRUCTURES Simple If: if (boolean exp) { statements.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
Particles and their home in Geometry Shaders Paul Taylor 2010.
Emerging Technologies for Games Capability Testing and DirectX10 Features CO3301 Week 6.
OpenGL Shading Language
Advanced D3D10 Shader Authoring Presentation/Presenter Title Slide.
3D Game Programming Homework Assignment # 4 Combat System The scene data (in the HW04 folder) : battle_field.cwn The terrain data (in the HW04 folder)
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
Real-Time Rendering Geometry and Buffers
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Programmable Hardware
GraphGame ggl011-Particles
Programming with OpenGL Part 3: Shaders
Development of a particle system
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

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 project rename project working dir: $(SolutionDir) Project Properties/Configuration Properties/Debugging/Command Arguments --solutionPath:"$(SolutionDir)" --projectPath:"$(ProjectDir)" build, run

#include "Math/math.h" class Particle { friend class Game; Egg::Math::float3 position; Egg::Math::float3 velocity; float lifespan; float age; public: };

void reborn() { using namespace Egg::Math; position = float3::random(-1,1); velocity = position * 5; age = 0; lifespan = float1::random(2,5); } Particle(){ reborn(); }

Lehetne ezeket kézzel létrehozni – ugyanúgy, ahogy a háromszögrajzolásnál az elején – csak a shader az effect fileból jön D3DX11_PASS_DESC billboardPassDesc; effect->GetTechniqueByName("billboard")-> GetPassByName("fire")->GetDesc(&billboardPassDesc); – és a VB használati módja dinamikus – rajzoláskor context->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST); effect->GetTechniqueByName("billboard")-> GetPassByName("fire")->Apply(0, context); context->Draw(particles.size(), 0);

Mesh::VertexStream a buffer Effect pass-ra Mesh::Material InputLayout gyártása a Mesh::Binder feladata a végén kapunk egy Mesh::Shaded-et amit csak ki kell rajzolni – beállítja az effect pass-t – az input layoutot – a vertex buffert – rajzol

#include "Particle.h" #include

class Game : public Egg::Sas::SasApp { std::vector particles; Egg::Mesh::Shaded::P fireBillboardSet;

for(int i=0; i<40; i++) particles.push_back(Particle());

D3D11_INPUT_ELEMENT_DESC particleElements[3]; particleElements[0].AlignedByteOffset = offsetof(Particle, position); particleElements[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; particleElements[0].InputSlot = 0; particleElements[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; particleElements[0].InstanceDataStepRate = 0; particleElements[0].SemanticIndex = 0; particleElements[0].SemanticName = "POSITION"; particleElements[1].AlignedByteOffset = offsetof(Particle, lifespan); particleElements[1].Format = DXGI_FORMAT_R32_FLOAT; particleElements[1].InputSlot = 0; particleElements[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; particleElements[1].InstanceDataStepRate = 0; particleElements[1].SemanticIndex = 0; particleElements[1].SemanticName = "LIFESPAN"; particleElements[2].AlignedByteOffset = offsetof(Particle, age); particleElements[2].Format = DXGI_FORMAT_R32_FLOAT; particleElements[2].InputSlot = 0; particleElements[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; particleElements[2].InstanceDataStepRate = 0; particleElements[2].SemanticIndex = 0; particleElements[2].SemanticName = "AGE";

Egg::Mesh::VertexStreamDesc particleBufferDesc; particleBufferDesc.elements = particleElements; particleBufferDesc.nElements = 3; particleBufferDesc.nVertices = particles.size(); particleBufferDesc.vertexStride = sizeof(Particle); particleBufferDesc.vertexData = &particles.at(0); particleBufferDesc.cpuAccessFlags = D3D11_CPU_ACCESS_WRITE; particleBufferDesc.usage = D3D11_USAGE_DYNAMIC;

Egg::Mesh::VertexStream::P particleVertexStream = Egg::Mesh::VertexStream::create( device, particleBufferDesc);

ID3DX11EffectPass* billboardPass = effect-> GetTechniqueByName("billboard")-> GetPassByName("fire"); Egg::Mesh::Material::P fireMaterial = Egg::Mesh::Material::create( billboardPass, 0); fireBillboardSet = binder->bindMaterial( fireMaterial, particleVertexStream);

fireBillboardSet.reset();

fireBillboardSet->draw(context);

solution fx folderbe billboard.fx

#include #9.0

struct IaosBillboard { float3 pos : POSITION; float lifespan : LIFESPAN; float age : AGE; }; typedef IaosBillboard VsosBillboard; VsosBillboard vsBillboard(IaosBillboard input) { return input; } #9.0

struct GsosBillboard { float4 pos : SV_Position; float2 tex : TEXCOORD; }; float billboardWidth = 0.1; float billboardHeight = 0.1; #9.0

[maxvertexcount(4)] void gsBillboard( point VsosBillboard input[1], inout TriangleStream stream) { float4 hndcPos = mul(float4(input[0].pos, 1), modelViewProjMatrix); GsosBillboard output; output.pos = hndcPos; output.pos.x += billboardWidth; output.pos.y += billboardHeight; output.tex = float2(1, 0); stream.Append(output); output.pos = hndcPos; output.pos.x += billboardWidth; output.pos.y -= billboardHeight; output.tex = float2(1, 1); stream.Append(output); output.pos = hndcPos; output.pos.x -= billboardWidth; output.pos.y += billboardHeight; output.tex = float2(0, 0); stream.Append(output); output.pos = hndcPos; output.pos.x -= billboardWidth; output.pos.y -= billboardHeight; output.tex = float2(0, 1); stream.Append(output); } #9.0

float4 psFire(GsosBillboard input) : SV_Target { return input.tex.xyyy; } technique11 billboard { pass fire { SetVertexShader ( CompileShader( vs_5_0, vsBillboard() ) ); SetGeometryShader ( CompileShader( gs_5_0, gsBillboard() ) ); SetPixelShader( CompileShader( ps_5_0, psFire() ) ); } #9.0

particle.dds letöltése Projects/gg011-Particles/Media folderbe

class Game : public Egg::Sas::SasApp { ID3D11ShaderResourceView* billboardSrv;

D3DX11CreateShaderResourceViewFromFileA( device, systemEnvironment.resolveMediaPath( "particle.dds" ).c_str(), NULL, NULL, &billboardSrv, NULL); effect-> GetVariableByName("billboardTexture") ->AsShaderResource(billboardSrv);

billboardSrv->Release();

Texture2D billboardTexture; float4 psFire(GsosBillboard input) : SV_Target { return billboardTexture.Sample( linearSampler, input.tex.xy); } #9.0

using namespace Egg::Math; float4 worldBillboardSize(0.2, 0.2, 0, 0); float4 screenBillboardSize = worldBillboardSize * firstPersonCam->getProjMatrix(); effect-> GetVariableByName("billboardWidth")-> AsScalar()-> SetFloat(screenBillboardSize.x); effect-> GetVariableByName("billboardHeight")-> AsScalar()-> SetFloat(screenBillboardSize.y);

BlendState-et kell definiálni, pass-ban kiválasztani a többi pass-ban viszont vissza kéne állítani legyen a blendStates.fx, amibe az összes BlendState-et gyűjtjük legyen akkor már – rasterizerStates.fx – depthStencilStates.fx

BlendState defaultBlender { }; BlendState additiveBlender { BlendEnable[0] = true; SrcBlend = src_alpha; DestBlend = one; BlendOp = add; SrcBlendAlpha = one; DestBlendAlpha = one; BlendOpAlpha = add; }; #9.0

RasterizerState defaultRasterizer { }; RasterizerState noCullRasterizer { CullMode = none; FillMode = solid; }; RasterizerState backfaceRasterizer { CullMode = front; FillMode = solid; }; RasterizerState wireframeRasterizer { CullMode = none; FillMode = wireFrame; }; #9.0

DepthStencilState defaultCompositor { }; DepthStencilState noDepthTestCompositor { DepthEnable = false; DepthWriteMask = zero; }; DepthStencilState noDepthWriteCompositor { DepthEnable = true; DepthWriteMask = zero; }; #9.0

#include... technique11 basic { pass basic { SetVertexShader ( CompileShader( vs_5_0, vsTrafo() ) ); SetGeometryShader( NULL ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psBasic() ) ); SetDepthStencilState( defaultCompositor, 0 ); SetBlendState( defaultBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); } #9.0

textured/textured shaded/diffuse, shaded/specular envmapped/envmapped, envmapped/background

technique11 billboard { pass fire { SetVertexShader ( CompileShader( vs_5_0, vsBillboard() ) ); SetGeometryShader ( CompileShader( gs_5_0, gsBillboard() ) ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psFire() ) ); SetDepthStencilState( defaultCompositor, 0 ); SetBlendState( defaultBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); } #9.0

technique11 billboard { pass fire { SetVertexShader ( CompileShader( vs_5_0, vsBillboard() ) ); SetGeometryShader ( CompileShader( gs_5_0, gsBillboard() ) ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psFire() ) ); SetDepthStencilState( defaultCompositor, 0 ); SetBlendState( additiveBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); } #9.0

technique11 billboard { pass fire { SetVertexShader ( CompileShader( vs_5_0, vsBillboard() ) ); SetGeometryShader ( CompileShader( gs_5_0, gsBillboard() ) ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psFire() ) ); SetDepthStencilState( noDepthTestCompositor, 0 ); SetBlendState( additiveBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); } #9.0

technique11 billboard { pass fire { SetVertexShader ( CompileShader( vs_5_0, vsBillboard() ) ); SetGeometryShader ( CompileShader( gs_5_0, gsBillboard() ) ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psFire() ) ); SetDepthStencilState( noDepthWriteCompositor, 0 ); SetBlendState( additiveBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); } #9.0

technique11 billboard { pass fire { SetVertexShader ( CompileShader( vs_5_0, vsBillboard() ) ); SetGeometryShader ( CompileShader( gs_5_0, gsBillboard() ) ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psFire() ) ); SetDepthStencilState( noDepthWriteCompositor, 0 ); SetBlendState( transparencyBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); } #9.0

Ehhez rendezni kellene a plakátokat mélység szerint… egyelőre inkább vissza az additívhoz!

float4 psFire(GsosBillboard input) : SV_Target { float4 color = billboardTexture.Sample(linearSampler, input.tex.xy); color.rgb = float3( color.a, pow(color.a, 4), pow(color.a, 10)); return color; } #9.0

using namespace Egg::Math; firstPersonCam = Egg::Cam::FirstPerson::create() ->setView( float3(0, 0, 200), float3(0, 0, -1)) ->setProj(1.2, 1, 1, 1000) ->setSpeed(50); float4 worldBillboardSize(50.0, 50.0, 0, 0);

void move(float dt) { position +=velocity * dt; age += dt; if(age > lifespan) reborn(); }

for(int i = 0; i < particles.size(); i++) particles.at(i).move(dt);

ID3D11Buffer* vertexBuffer = fireBillboardSet->getGeometry()-> getPrimaryBuffer(); ID3D11DeviceContext* context; device->GetImmediateContext(&context); D3D11_MAPPED_SUBRESOURCE mappedVertexData; context->Map(vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedVertexData); memcpy(mappedVertexData.pData, &particles.at(0), sizeof(Particle) * particles.size()); context->Unmap(vertexBuffer, 0); context->Release();

Korfüggő méret, intenzitás és átlátszóság

struct GsosBillboard { float4 pos : SV_Position; float2 tex : TEXCOORD; float opacity : OPACITY; }; float s = input[0].age / input[0].lifespan;... output.opacity = 1 - abs(s*2-1); // és mindenhol szorozzuk s-sel a szélességet és magasságot #9.0

float4 psFire(GsosBillboard input) : SV_Target { float4 color = billboardTexture.Sample(linearSampler, input.tex.xy); color.rgb = float3(color.a, pow(color.a, 4), pow(color.a, 10)); color.a *= input.opacity; return color; } #9.0

technique11 billboard { pass fire { SetVertexShader ( CompileShader( vs_5_0, vsBillboard() ) ); SetGeometryShader ( CompileShader( gs_5_0, gsBillboard() ) ); SetRasterizerState( defaultRasterizer ); SetPixelShader( CompileShader( ps_5_0, psFire() ) ); SetDepthStencilState( noDepthWriteCompositor, 0 ); SetBlendState( transparencyBlender, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF ); } #9.0

using namespace Egg::Math; struct CameraDepthComparator { float3 ahead; bool operator()(const Particle& a, const Particle& b) { return a.position.dot(ahead) > b.position.dot(ahead) ; } } comp = { firstPersonCam->getAhead() }; std::sort(particles.begin(), particles.end(), comp);