Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ogre3D Compositor Framework. Kezdeti teendők OgrePostProcBase.zip letöltése Útvonalak beállítása Fordítás futtatás.

Similar presentations


Presentation on theme: "Ogre3D Compositor Framework. Kezdeti teendők OgrePostProcBase.zip letöltése Útvonalak beállítása Fordítás futtatás."— Presentation transcript:

1 Ogre3D Compositor Framework

2 Kezdeti teendők OgrePostProcBase.zip letöltése Útvonalak beállítása Fordítás futtatás

3 Futtatás

4 OgrePostProc.cpp … void setupPostProc() { } void setupScene() { … } int _tmain(int argc, _TCHAR* argv[]) { … setupScene(); setupListeners(); setupPostProc(); … }

5 \ bin\media\monochrome.compositor compositor Monochrome { technique { texture scene target_width target_height PF_FLOAT16_RGBA target scene { input previous } target_output { input none pass render_quad { material PostProc/Monochrome input 0 scene }

6 \bin\media\PostProc.material vertex_program FSQuadVS hlsl { source PostProc.hlsl entry_point FS_QUAD_VS target vs_2_0 } fragment_program MonochromePS hlsl { source PostProc.hlsl entry_point Monochrome_PS target ps_2_0 }

7 \bin\media\PostProc.material material PostProc/Monochrome { technique { pass { vertex_program_ref FSQuadVS { } fragment_program_ref MonochromePS { param_named_auto width viewport_width param_named_auto height viewport_height } texture_unit { filtering none tex_address_mode clamp }

8 \bin\media\PostProc.hlsl struct VS_OUT { float4 hPosition: POSITION; float2 texCoord: TEXCOORD0; }; VS_OUT FS_QUAD_VS(float4 position : POSITION, float4 texCoord : TEXCOORD0) { VS_OUT OUT; OUT.hPosition = float4(sign(position.xy),0,1); OUT.texCoord = (float2(OUT.hPosition.x, -OUT.hPosition.y) + 1.0) / 2.0; return OUT; }

9 \bin\media\PostProc.hlsl float4 Monochrome_PS(VS_OUT IN, uniform float width, uniform float height, uniform sampler2D Image: register(s0) ):COLOR { IN.texCoord += float2(0.5/width, 0.5/height); float4 sample = tex2D(Image,IN.texCoord ); // D65 white conversion and weighting float avg = sample.r * 0.21f + sample.g * 0.39f + sample.b * 0.4f; return float4(avg, avg, avg, 1); }

10 OgrePostProc.cpp void setupPostProc() { CompositorManager::getSingleton().addCompositor(renderWindow->getViewport(0), "Monochrome"); CompositorManager::getSingleton().setCompositorEnabled(renderWindow->getViewport(0), "Monochrome", true); }

11 Próba

12 Önálló feladat Ne szürke legyen Lehet sepia pl. vagy zöld (éjszakai kamera) vagy vörös Állítsuk vissza szürkére

13 Feladat Új compositor: motion blur Csak másoljuk az eredeti képet DE Alhpa blending-el kombinálva az előző képpel Figyelni kell a rendertarget kezdeti tartalmára Megoldás…

14 motionblur.compositor compositor MotionBlur { technique { texture scene target_width target_height PF_FLOAT16_RGBA target scene { input previous } target_output { input none pass render_quad { clear { buffers depth } material PostProc/BlendedCopy input 0 scene }

15 PostProc.material fragment_program CopyPS hlsl { source PostProc.hlsl entry_point Copy_PS target ps_2_0 } material PostProc/BlendedCopy { technique { pass { vertex_program_ref FSQuadVS { } fragment_program_ref CopyPS { param_named_auto width viewport_width param_named_auto height viewport_height param_named alpha float 20 param_named_auto dt frame_time } scene_blend alpha_blend texture_unit { filtering none tex_address_mode clamp }

16 PostProc.hlsl float4 Copy_PS(VS_OUT IN, uniform float width, uniform float height, uniform float alpha, uniform float dt, uniform sampler2D Image: register(s0) ):COLOR { IN.texCoord += float2(0.5/width, 0.5/height); float4 sample = tex2D(Image, IN.texCoord); return float4(sample.rgb, alpha * dt); }

17 OgrePostProc.cpp void setupPostProc() { renderWindow->getViewport(0)->setClearEveryFrame(true, FBT_DEPTH); Root::getSingleton().getRenderSystem()->clearFrameBuffer( FBT_COLOUR, ColourValue::Black); CompositorManager::getSingleton().addCompositor(renderWindow->getViewport(0), "Monochrome"); CompositorManager::getSingleton().setCompositorEnabled(renderWindow->getViewport(0), "Monochrome", true); CompositorManager::getSingleton().addCompositor(renderWindow->getViewport(0), "MotionBlur"); CompositorManager::getSingleton().setCompositorEnabled(renderWindow->getViewport(0), "MotionBlur", true); }

18 Glow

19 glow.compositor compositor Glow { technique { texture scene target_width target_height PF_FLOAT16_RGBA texture cut 256 256 PF_FLOAT16_RGBA texture rt0 256 256 PF_FLOAT16_RGBA texture rt1 256 256 PF_FLOAT16_RGBA target rt1 { input none only_initial on pass clear { } target scene { input previous }

20 glow.compositor folyt. target cut { input none pass render_quad { material PostProc/GlowCut input 0 scene input 1 rt1 } target rt0 { input none pass render_quad { material PostProc/BlurV input 0 cut }

21 glow.compositor vége target rt1 { input none pass render_quad { material PostProc/BlurH input 0 rt0 } target_output { input none pass render_quad { material PostProc/Add input 0 scene input 1 rt1 }

22 PostProc.material material PostProc/Copy { technique { pass { vertex_program_ref FSQuadVS { } fragment_program_ref CopyPS { param_named_auto width viewport_width param_named_auto height viewport_height param_named alpha float 1 param_named dt float 1 } texture_unit { //filtering none tex_address_mode clamp }

23 PostProc.material fragment_program GlowCutPS hlsl { source PostProc.hlsl entry_point GlowCut_PS target ps_2_0 } material PostProc/GlowCut { technique { pass { vertex_program_ref FSQuadVS { } fragment_program_ref GlowCutPS { param_named_auto width viewport_width param_named_auto height viewport_height param_named cutValue float 3 param_named timeBlur float 0.8 } texture_unit { tex_address_mode clamp } texture_unit { tex_address_mode clamp }

24 PostProc.material fragment_program AddPS hlsl { source PostProc.hlsl entry_point Add_PS target ps_2_0 } material PostProc/Add { technique { pass { vertex_program_ref FSQuadVS { } fragment_program_ref AddPS { param_named_auto width viewport_width param_named_auto height viewport_height } texture_unit { tex_address_mode clamp } texture_unit { tex_address_mode clamp }

25 PostProc.material fragment_program BlurVPS hlsl { source PostProc.hlsl entry_point BlurV_PS target ps_2_0 } material PostProc/BlurV { technique { pass { vertex_program_ref FSQuadVS { } fragment_program_ref BlurVPS { param_named_auto width viewport_width param_named_auto height viewport_height param_named stretch float 1.2 } texture_unit { tex_address_mode clamp }

26 PostProc.material fragment_program BlurHPS hlsl { source PostProc.hlsl entry_point BlurH_PS target ps_2_0 } material PostProc/BlurH { technique { pass { vertex_program_ref FSQuadVS { } fragment_program_ref BlurHPS { param_named_auto width viewport_width param_named_auto height viewport_height param_named stretch float 1.2 } texture_unit { tex_address_mode clamp }

27 PostProc.hlsl float4 Add_PS(VS_OUT IN, uniform float width, uniform float height, uniform sampler2D Image1: register(s0), uniform sampler2D Image2: register(s1) ):COLOR { IN.texCoord += float2(0.5/width, 0.5/height); float4 sample1 = tex2D(Image1, IN.texCoord); float4 sample2 = tex2D(Image2, IN.texCoord); return sample1 + sample2; }

28 PostProc.hlsl float4 GlowCut_PS(VS_OUT IN, uniform float width, uniform float height, uniform float timeBlur, uniform float cutValue, uniform sampler2D Image: register(s0), uniform sampler2D prevImage: register(s1) ):COLOR { IN.texCoord += float2(0.5/width, 0.5/height); float4 sample = tex2D(Image, IN.texCoord); float lum = dot(sample.rgb, float3(0.21f, 0.39f, 0.4f)); if (lum < cutValue) sample = float4(0,0,0,1); float4 sample2 = tex2D(prevImage, IN.texCoord); sample = lerp(sample2, sample, timeBlur); return sample; }

29 PostProc.hlsl float4 BlurV_PS(VS_OUT IN, uniform float width, uniform float height, uniform float stretch, uniform sampler2D Image: register(s0) ):COLOR { float2 tex0 = IN.texCoord + float2(0.5/width, 0.5/height); float4 texLookUp_v = tex2D(Image, float2(tex0.x, tex0.y-(3.86979f*stretch/height)))+ tex2D(Image, float2(tex0.x, tex0.y-(1.72291f*stretch/height)))+ tex2D(Image, tex0)+ tex2D(Image, float2(tex0.x, tex0.y+(1.72291f*stretch/height)))+ tex2D(Image, float2(tex0.x, tex0.y+(3.86979f*stretch/height))); return texLookUp_v / 5.0; }

30 PostProc.hlsl float4 BlurH_PS(VS_OUT IN, uniform float width, uniform float height, uniform float stretch, uniform sampler2D Image: register(s0) ) : COLOR { float2 tex0 = IN.texCoord + float2(0.5/width, 0.5/height); float4 texLookUp_h = tex2D(Image, float2(tex0.x-(3.86979f*stretch/width), tex0.y)) + tex2D(Image, float2(tex0.x-(1.72291f*stretch/width ), tex0.y)) + tex2D(Image, tex0) + tex2D(Image, float2(tex0.x+(1.72291f*stretch/width), tex0.y)) + tex2D(Image, float2(tex0.x+(3.86979f*stretch/width), tex0.y)); return texLookUp_h / 5.0; }

31 OgrePostProc.cpp void setupPostProc() { renderWindow->getViewport(0)->setClearEveryFrame(true, FBT_DEPTH); Root::getSingleton().getRenderSystem()->clearFrameBuffer( FBT_COLOUR, ColourValue::Black); CompositorManager::getSingleton(). addCompositor(renderWindow->getViewport(0), "Glow"); CompositorManager::getSingleton(). setCompositorEnabled(renderWindow->getViewport(0), "Glow", true); … }

32 Próba

33 Tone Mapping

34 Tonemap.compositor compositor ToneMap { technique { texture scene target_width target_height PF_FLOAT16_RGBA texture luminance target_width target_height PF_FLOAT16_RGBA texture rt0 512 512 PF_FLOAT16_RGBA texture rt1 128 128 PF_FLOAT16_RGBA texture rt2 32 32 PF_FLOAT16_RGBA texture rt3 8 8 PF_FLOAT16_RGBA texture rt4 2 2 PF_FLOAT16_RGBA texture globalLum 2 2 PF_FLOAT16_RGBA target scene { input previous }

35 Tonemap.compositor folytatás.. target luminance { input none pass render_quad { material PostProc/Monochrome input 0 scene } target rt0 { input none pass render_quad { material PostProc/BlurV input 0 luminance }

36 Tonemap.compositor folytatás.. target rt1 { input none pass render_quad { material PostProc/BlurH input 0 rt0 } target rt2 { input none pass render_quad { material PostProc/BlurV input 0 rt1 }

37 Tonemap.compositor folytatás.. target rt3 { input none pass render_quad { material PostProc/BlurH input 0 rt2 } target rt4 { input none pass render_quad { material PostProc/BlurV input 0 rt3 }

38 Tonemap.compositor folytatás.. target globalLum { input none only_initial on pass clear { } target globalLum { input none pass render_quad { clear { buffers depth } material PostProc/BlendedCopy input 0 rt4 }

39 Tonemap.compositor vége target_output { input none pass render_quad { material PostProc/ToneMap input 0 scene input 1 luminance input 2 globalLum }

40 PostProc.material fragment_program ToneMapPS hlsl { source PostProc.hlsl entry_point ToneMap_PS target ps_2_0 } material PostProc/ToneMap { technique { pass { vertex_program_ref FSQuadVS { } fragment_program_ref ToneMapPS { param_named_auto width viewport_width param_named_auto height viewport_height param_named alpha float 0.4 param_named wLum2 float 0.7 } texture_unit { } texture_unit { } texture_unit { }

41 PostProc.hlsl float4 ToneMap_PS(VS_OUT IN, uniform float width, uniform float height, uniform float alpha, uniform float wLum2, uniform sampler2D Image: register(s0), uniform sampler2D Luminance: register(s1), uniform sampler2D GlobalLuminance: register(s2) ):COLOR { IN.texCoord += float2(0.5/width, 0.5/height); float lum = tex2D(Luminance, IN.texCoord).r; // Luminance of pixel float gLum = tex2D(GlobalLuminance, float2(0.5,0.5)).r;// Global luminance float rLum = alpha * lum / gLum; // Relative luminance float D = rLum * (1 + rLum / wLum2) / (1 + rLum); float4 color = tex2D(Image, IN.texCoord); color.rgb *= D / lum; // tone mapping return color; }

42 OgrePostProc.cpp void setupPostProc() { renderWindow->getViewport(0)->setClearEveryFrame(true, FBT_DEPTH); Root::getSingleton().getRenderSystem()->clearFrameBuffer( FBT_COLOUR, ColourValue::Black); CompositorManager::getSingleton().addCompositor(renderWindow->getViewport(0), "Glow"); CompositorManager::getSingleton().setCompositorEnabled(renderWindow->getViewport(0), "Glow", true); CompositorManager::getSingleton().addCompositor(renderWindow->getViewport(0), "ToneMap"); CompositorManager::getSingleton().setCompositorEnabled(renderWindow->getViewport(0), "ToneMap", true); }

43 Próba

44 Depth of field

45 OgrePostProc.cpp void setupScene() { … Texture* sceneDepthMap = TextureManager::getSingleton().createManual("sceneDepthMap", "default„, TEX_TYPE_2D, viewport->getActualWidth(), viewport->getActualHeight(), 0, 0, PF_FLOAT16_RGBA, TU_RENDERTARGET).getPointer(); HardwarePixelBuffer* hpb = (sceneDepthMap->getBuffer(0, 0)).getPointer(); RenderTarget* rt = hpb->getRenderTarget(0); Viewport* v = rt->addViewport(camera); v->setOverlaysEnabled(false); v->setMaterialScheme("SceneInfo"); SceneNode* levelNode = rootNode->createChildSceneNode();

46 level1.material vertex_program SceneInfoVS hlsl { source SceneInfo.hlsl entry_point vs target vs_2_0 } fragment_program SceneInfoPS hlsl { source SceneInfo.hlsl entry_point ps target ps_2_0 }

47 level1.material material level1/base { technique sceneinfo { scheme SceneInfo pass { vertex_program_ref SceneInfoVS { param_named_auto ModelViewProj worldviewproj_matrix param_named_auto Model world_matrix } fragment_program_ref SceneInfoPS { }

48 SceneInfo.hlsl struct VERTEX_IN { float4 position :POSITION; }; struct VERTEX_OUT { float4 position :POSITION; float3 wPos :TEXCOORD0; float4 hPos :TEXCOORD2; }; VERTEX_OUT vs(VERTEX_IN IN, uniform float4x4 ModelViewProj, uniform float4x4 Model) { VERTEX_OUT OUT = (VERTEX_OUT) 0; OUT.position = OUT.hPos = mul(ModelViewProj, IN.position); OUT.wPos = mul(Model, IN.position).xyz; return OUT; } float4 ps(VERTEX_OUT IN):COLOR0 { float hZ = IN.hPos.z / IN.hPos.w; return float4(hZ, IN.wPos); }

49 dof.compositor compositor DepthOfField { technique { texture scene target_width target_height PF_FLOAT16_RGBA target scene { input previous } target_output { input none pass render_quad { material PostProc/DoF input 0 scene }

50 fragment_program DoFPS hlsl { source PostProc.hlsl entry_point DoF_PS target ps_2_0 } material PostProc/DoF { technique { pass { vertex_program_ref FSQuadVS { } fragment_program_ref DoFPS { param_named_auto width viewport_width param_named_auto height viewport_height param_named scale float 80 } texture_unit { } texture_unit { texture sceneDepthMap } PostProc.material

51 PostProc.hlsl static const float2 filterTaps[] = { float2(-0.326212f, -0.405805f), float2(-0.840144f, -0.07358f), float2(-0.695914f, 0.457137f), float2(-0.203345f, 0.620716f), float2(0.96234f, -0.194983f), float2(0.473434f, -0.480026f), float2(0.519456f, 0.767022f), float2(0.185461f, -0.893124f), float2(0.507431f, 0.064425f), float2(0.89642f, 0.412458f), float2(-0.32194f, -0.932615f), float2(-0.791559f, -0.597705f) };

52 float4 DoF_PS(VS_OUT IN, uniform float width, uniform float height, uniform float scale, uniform sampler2D Image: register(s0), uniform sampler2D SceneInfo: register(s1) ):COLOR { IN.texCoord += float2(0.5/width, 0.5/height); float dx = 1.0f / width; float dy = 1.0f / height; // Depth based blur float4 colorSum = tex2D(Image, IN.texCoord); // Center sample float depth = tex2D(SceneInfo, IN.texCoord).r; // Center sample float focalDist = tex2D(SceneInfo, float2(0.5,0.5)).r; float sizeCoC = abs(depth - focalDist) * scale; for (int i = 0; i < 12; i++) // Filter { float2 tapCoord = IN.texCoord + filterTaps[i] * float2(dx,dy) * sizeCoC; //Tap coords colorSum += tex2D(Image, tapCoord); } return colorSum / 12; // Normalize } PostProc.hlsl

53 OgrePostProc.cpp void setupPostProc() { renderWindow->getViewport(0)->setClearEveryFrame(true, FBT_DEPTH); Root::getSingleton().getRenderSystem()->clearFrameBuffer( FBT_COLOUR, ColourValue::Black); CompositorManager::getSingleton().addCompositor(renderWindow->getViewport(0), "DepthOfField"); CompositorManager::getSingleton().setCompositorEnabled(renderWindow->getViewport(0), "DepthOfField", true);

54 Próba

55 Light shafts

56 Lightshaft.compositor compositor LightShaft { technique { texture scene target_width target_height PF_FLOAT16_RGBA target scene { input previous } target_output { input none pass render_quad { identifier 1 material PostProc/LightShaft input 0 scene }

57 fragment_program LightShaftPS hlsl { source PostProc.hlsl entry_point LightShaft_PS target ps_3_0 } material PostProc/LightShaft { technique { pass { vertex_program_ref FSQuadVS { param_named_auto InvViewProj inverse_viewproj_matrix } fragment_program_ref LightShaftPS { param_named_auto width viewport_width param_named_auto height viewport_height } texture_unit { } texture_unit { texture sceneDepthMap } texture_unit { texture shadowCubeMap } PostProc.material

58 float4 LightShaft_PS(VS_OUT IN, uniform float width, uniform float height, uniform float4 camPos, uniform float3 lightPos, uniform float lightRange, uniform sampler2D Image: register(s0), uniform sampler2D SceneInfo: register(s1), uniform samplerCUBE shadowCubeMap: register(s2) ):COLOR { static const float samplecount = 200; static const float density = 0.02; static const float albedo = 0.5; static const float shadowBias = 0.001; IN.texCoord += float2(0.5/width, 0.5/height); … PostProc.hlsl

59 float3 wPos = tex2D(SceneInfo, IN.texCoord).yzw; float3 dir = camPos.xyz - wPos; float dist = length(dir); float dt = 1.0 / samplecount * dist; dir *= dt / dist; float3 cubePos = wPos - lightPos; float I = 1000; float4 L = 0;//tex2D(Image, IN.texCoord); for(int i = 0; i < samplecount; i++) { cubePos += dir; float d = length(cubePos) / lightRange; float dstored = texCUBE(shadowCubeMap,float3(cubePos.xy, -cubePos.z)).r; float shadow = (float)(d - shadowBias < dstored); L = L * (exp(-dt*density)) + I * shadow * exp(-d * density) / (12.56) * albedo * (1.0 - exp(-dt*density)); } return tex2D(Image, IN.texCoord) + L; } PostProc.hlsl

60 OgrePostProc.cpp class LSCompListener : public CompositorInstance::Listener { void notifyMaterialRender(uint32 pass_id, MaterialPtr &mat) { if(pass_id == 1) { GpuProgramParametersSharedPtr fparams = mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters(); fparams->setNamedConstant("lightPos", Vector3(0,20,-200)); fparams->setNamedConstant("lightRange", 600.0f); fparams->setNamedConstant("camPos", camera->getPosition()); } };

61 OgrePostProc.cpp void setupPostProc() { renderWindow->getViewport(0)->setClearEveryFrame(true, FBT_DEPTH); Root::getSingleton().getRenderSystem()->clearFrameBuffer( FBT_COLOUR, ColourValue::Black); CompositorInstance* lightShaftComp = CompositorManager::getSingleton().addCompositor(renderWindow->getViewport(0), "LightShaft"); CompositorManager::getSingleton().setCompositorEnabled(renderWindow->getViewport(0), "LightShaft", true); lightShaftComp->addListener(new LSCompListener()); CompositorManager::getSingleton().addCompositor(renderWindow->getViewport(0), "DepthOfField"); …

62 Próba


Download ppt "Ogre3D Compositor Framework. Kezdeti teendők OgrePostProcBase.zip letöltése Útvonalak beállítása Fordítás futtatás."

Similar presentations


Ads by Google