public virtual void setBillboardOrigin(BillboardOrigin origin) { OgrePINVOKE.BillboardSet_setBillboardOrigin(swigCPtr, (int)origin); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } }
public virtual BillboardOrigin getBillboardOrigin() { BillboardOrigin ret = (BillboardOrigin)OgrePINVOKE.BillboardSet_getBillboardOrigin(swigCPtr); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
/// <summary> /// /// </summary> /// <param name="matP"></param> /// <param name="origin"></param> public static void AddMaterialRef(Material matP, BillboardOrigin origin) { Material mat = matP; SBMaterialRef matRef = null; if (!mSelfList.TryGetValue(mat, out matRef)) { matRef = new SBMaterialRef(mat, origin); } else { //its allready there, increase the refcount matRef.mRefCount++; } }
/// <summary> /// /// </summary> /// <param name="group"></param> /// <param name="entity"></param> protected ImpostorBatch(ImpostorPage group, Entity entity) { //Render impostor texture for this entity mTex = ImpostorTexture.GetTexture(group, entity); //Create billboard set mBBSet = new StaticBillboardSet(group.SceneManager, group.PagedGeometry.SceneNode); mBBSet.SetTextureStacksAndSlices(ImpostorTexture.ImpostorPitchAngles, ImpostorTexture.ImpostorYawAngles); BillboardOrigin = ImpostorPage.ImpostorPivot; //Default the angle to 0 degrees mPitchIndex = -1; mYawIndex = -1; SetAngle(0.0f, 0.0f); }
/// <summary> /// /// </summary> /// <param name="mgr"></param> /// <param name="rootSceneNode"></param> /// <param name="method"></param> public StaticBillboardSet(SceneManager mgr, SceneNode rootSceneNode, BillboardMethod method) { mSceneMgr = mgr; mRenderMethod = method; mVisible = true; mFadeEnabled = false; mBBOrigin = BillboardOrigin.Center; //Fall back to Compatible if vertex shaders are not available if (mRenderMethod == BillboardMethod.Accelerated) { RenderSystemCapabilities caps = Root.Singleton.RenderSystem.Capabilities; if (!caps.HasCapability(Capabilities.VertexPrograms)) mRenderMethod = BillboardMethod.Compatible; } mNode = rootSceneNode.CreateChildSceneNode(); mEntityName = GetUniqueID("SBSEntity"); if (mRenderMethod == BillboardMethod.Accelerated) { //Accelerated billboard method mEntity = null; mUFactor = 1.0f; mVFactor = 1.0f; //Load vertex shader to align billboards to face the camera (if not loaded already) if (++mSelfInstances == 1) { //First shader, simple camera-alignment HighLevelGpuProgram vertexShader = (HighLevelGpuProgram)HighLevelGpuProgramManager.Instance.GetByName("Sprite_vp"); if (vertexShader == null) { string vertexProg = string.Empty; vertexProg = "void Sprite_vp( \n" + " float4 position : POSITION, \n" + " float3 normal : NORMAL, \n" + " float4 color : COLOR, \n" + " float2 uv : TEXCOORD0, \n" + " out float4 oPosition : POSITION, \n" + " out float2 oUv : TEXCOORD0, \n" + " out float4 oColor : COLOR, \n" + " out float4 oFog : FOG, \n" + " uniform float4x4 worldViewProj, \n" + " uniform float uScroll, \n" + " uniform float vScroll, \n" + " uniform float4 preRotatedQuad[4] ) \n" + "{ \n" + //Face the camera " float4 vCenter = float4( position.x, position.y, position.z, 1.0f ); \n" + " float4 vScale = float4( normal.x, normal.y, normal.x, 1.0f ); \n" + " oPosition = mul( worldViewProj, vCenter + (preRotatedQuad[normal.z] * vScale) ); \n" + //Color " oColor = color; \n" + //UV Scroll " oUv = uv; \n" + " oUv.x += uScroll; \n" + " oUv.y += vScroll; \n" + //Fog " oFog.x = oPosition.z; \n" + "}"; vertexShader = HighLevelGpuProgramManager.Instance.CreateProgram( "Sprite_vp", ResourceGroupManager.DefaultResourceGroupName, "cg", GpuProgramType.Vertex); vertexShader.Source = vertexProg; vertexShader.SetParam("profiles", "vs_1_1 arbvp1"); vertexShader.SetParam("entry_point", "Sprite_vp"); vertexShader.Load(); } //Second shader, camera alignment and distance based fading HighLevelGpuProgram vertexShader2 = (HighLevelGpuProgram)HighLevelGpuProgramManager.Instance.GetByName("SpriteFade_vp"); if (vertexShader2 == null) { string vertexProg2 = string.Empty; vertexProg2 = "void SpriteFade_vp( \n" + " float4 position : POSITION, \n" + " float3 normal : NORMAL, \n" + " float4 color : COLOR, \n" + " float2 uv : TEXCOORD0, \n" + " out float4 oPosition : POSITION, \n" + " out float2 oUv : TEXCOORD0, \n" + " out float4 oColor : COLOR, \n" + " out float4 oFog : FOG, \n" + " uniform float4x4 worldViewProj, \n" + " uniform float3 camPos, \n" + " uniform float fadeGap, \n" + " uniform float invisibleDist, \n" + " uniform float uScroll, \n" + " uniform float vScroll, \n" + " uniform float4 preRotatedQuad[4] ) \n" + "{ \n" + //Face the camera " float4 vCenter = float4( position.x, position.y, position.z, 1.0f ); \n" + " float4 vScale = float4( normal.x, normal.y, normal.x, 1.0f ); \n" + " oPosition = mul( worldViewProj, vCenter + (preRotatedQuad[normal.z] * vScale) ); \n" + " oColor.rgb = color.rgb; \n" + //Fade out in the distance " float dist = distance(camPos.xz, position.xz); \n" + " oColor.a = (invisibleDist - dist) / fadeGap; \n" + //UV scroll " oUv = uv; \n" + " oUv.x += uScroll; \n" + " oUv.y += vScroll; \n" + //Fog " oFog.x = oPosition.z; \n" + "}"; vertexShader2 = HighLevelGpuProgramManager.Instance.CreateProgram( "SpriteFade_vp", ResourceGroupManager.DefaultResourceGroupName, "cg", GpuProgramType.Vertex); vertexShader2.Source = vertexProg2; vertexShader2.SetParam("profiles", "vs_1_1 arbvp1"); vertexShader2.SetParam("entry_point", "SpriteFade_vp"); vertexShader2.Load(); } } } else { //Compatible billboard method mFallbackSet = mSceneMgr.CreateBillboardSet(GetUniqueID("SBS"), 100); mNode.AttachObject(mFallbackSet); } }
/// <summary> /// /// </summary> /// <param name="mat"></param> /// <param name="origin"></param> private SBMaterialRef(Material mat, BillboardOrigin origin) { mMaterial = mat; mOrigin = origin; mRefCount = 1; }
public static void UpdateAll(Vector3 cameraDirection) { if (mSelfInstances > 0)//selfInstances will only be greater than 0 if one or more StaticBillboardSet's are using BB_METHOD_ACCELERATED //Set shader parameter so material will face camera { Vector3 forward = cameraDirection; Vector3 vRight = forward.Cross(Vector3.UnitY); Vector3 vUp = forward.Cross(vRight); vRight.Normalize(); vUp.Normalize(); //Even if camera is upside down, the billboards should remain upright if (vUp.y < 0) { vUp *= -1; } //For each material in use by the billboard system.. foreach (SBMaterialRef it in SBMaterialRef.SelfList.Values) { Material mat = it.Material; BillboardOrigin bbOrigin = it.Origin; Vector3 vPoint0 = Vector3.Zero; Vector3 vPoint1 = Vector3.Zero; Vector3 vPoint2 = Vector3.Zero; Vector3 vPoint3 = Vector3.Zero; if (bbOrigin == BillboardOrigin.Center) { vPoint0 = (-vRight + vUp); vPoint1 = (vRight + vUp); vPoint2 = (-vRight - vUp); vPoint3 = (vRight - vUp); } else if (bbOrigin == BillboardOrigin.BottomCenter) { vPoint0 = (-vRight + vUp + vUp); vPoint1 = (vRight + vUp + vUp); vPoint2 = (-vRight); vPoint3 = (vRight); } //single prerotated quad oriented towards the camera float[] preRotatedQuad = { vPoint0.x, vPoint0.y, vPoint0.z, 0.0f, vPoint1.x, vPoint1.y, vPoint1.z, 0.0f, vPoint2.x, vPoint2.y, vPoint2.z, 0.0f, vPoint3.x, vPoint3.y, vPoint3.z, 0.0f }; Pass p = mat.GetTechnique(0).GetPass(0); if (!p.HasVertexProgram) { p.SetVertexProgram("Sprite_vp"); GpuProgramParameters gparams = p.VertexProgramParameters; gparams.SetNamedAutoConstant("worldViewProj", GpuProgramParameters.AutoConstantType.WorldViewProjMatrix, 0); gparams.SetNamedAutoConstant("uScroll", GpuProgramParameters.AutoConstantType.Custom, 0); gparams.SetNamedAutoConstant("vScroll", GpuProgramParameters.AutoConstantType.Custom, 0); gparams.SetNamedAutoConstant("preRotatedQuad[0]", GpuProgramParameters.AutoConstantType.Custom, 0); gparams.SetNamedAutoConstant("preRotatedQuad[1]", GpuProgramParameters.AutoConstantType.Custom, 0); gparams.SetNamedAutoConstant("preRotatedQuad[2]", GpuProgramParameters.AutoConstantType.Custom, 0); gparams.SetNamedAutoConstant("preRotatedQuad[3]", GpuProgramParameters.AutoConstantType.Custom, 0); } //Update the vertex shader parameters GpuProgramParameters gparams2 = p.VertexProgramParameters; for (int i = 0; i < preRotatedQuad.Length; i++) { gparams2.SetNamedConstant(string.Format("preRotatedQuad[{0}]", i), (Real)preRotatedQuad[i]); } //gparams2.SetNamedConstant("preRotatedQuad[0]", preRotatedQuad); gparams2.SetNamedConstant("uScroll", p.GetTextureUnitState(0).TextureScrollU); gparams2.SetNamedConstant("vScroll", p.GetTextureUnitState(0).TextureScrollV); } } }
/// <summary> /// /// </summary> /// <param name="mgr"></param> /// <param name="rootSceneNode"></param> /// <param name="method"></param> public StaticBillboardSet(SceneManager mgr, SceneNode rootSceneNode, BillboardMethod method) { mSceneMgr = mgr; mRenderMethod = method; mVisible = true; mFadeEnabled = false; mBBOrigin = BillboardOrigin.Center; //Fall back to Compatible if vertex shaders are not available if (mRenderMethod == BillboardMethod.Accelerated) { RenderSystemCapabilities caps = Root.Singleton.RenderSystem.Capabilities; if (!caps.HasCapability(Capabilities.VertexPrograms)) { mRenderMethod = BillboardMethod.Compatible; } } mNode = rootSceneNode.CreateChildSceneNode(); mEntityName = GetUniqueID("SBSEntity"); if (mRenderMethod == BillboardMethod.Accelerated) { //Accelerated billboard method mEntity = null; mUFactor = 1.0f; mVFactor = 1.0f; //Load vertex shader to align billboards to face the camera (if not loaded already) if (++mSelfInstances == 1) { //First shader, simple camera-alignment HighLevelGpuProgram vertexShader = (HighLevelGpuProgram)HighLevelGpuProgramManager.Instance.GetByName("Sprite_vp"); if (vertexShader == null) { string vertexProg = string.Empty; vertexProg = "void Sprite_vp( \n"+ " float4 position : POSITION, \n"+ " float3 normal : NORMAL, \n"+ " float4 color : COLOR, \n"+ " float2 uv : TEXCOORD0, \n"+ " out float4 oPosition : POSITION, \n"+ " out float2 oUv : TEXCOORD0, \n"+ " out float4 oColor : COLOR, \n"+ " out float4 oFog : FOG, \n"+ " uniform float4x4 worldViewProj, \n"+ " uniform float uScroll, \n"+ " uniform float vScroll, \n"+ " uniform float4 preRotatedQuad[4] ) \n"+ "{ \n"+ //Face the camera " float4 vCenter = float4( position.x, position.y, position.z, 1.0f ); \n"+ " float4 vScale = float4( normal.x, normal.y, normal.x, 1.0f ); \n"+ " oPosition = mul( worldViewProj, vCenter + (preRotatedQuad[normal.z] * vScale) ); \n"+ //Color " oColor = color; \n"+ //UV Scroll " oUv = uv; \n"+ " oUv.x += uScroll; \n"+ " oUv.y += vScroll; \n"+ //Fog " oFog.x = oPosition.z; \n"+ "}"; vertexShader = HighLevelGpuProgramManager.Instance.CreateProgram( "Sprite_vp", ResourceGroupManager.DefaultResourceGroupName, "cg", GpuProgramType.Vertex); vertexShader.Source = vertexProg; vertexShader.SetParam("profiles", "vs_1_1 arbvp1"); vertexShader.SetParam("entry_point", "Sprite_vp"); vertexShader.Load(); } //Second shader, camera alignment and distance based fading HighLevelGpuProgram vertexShader2 = (HighLevelGpuProgram)HighLevelGpuProgramManager.Instance.GetByName("SpriteFade_vp"); if (vertexShader2 == null) { string vertexProg2 = string.Empty; vertexProg2 = "void SpriteFade_vp( \n"+ " float4 position : POSITION, \n"+ " float3 normal : NORMAL, \n"+ " float4 color : COLOR, \n"+ " float2 uv : TEXCOORD0, \n"+ " out float4 oPosition : POSITION, \n"+ " out float2 oUv : TEXCOORD0, \n"+ " out float4 oColor : COLOR, \n"+ " out float4 oFog : FOG, \n"+ " uniform float4x4 worldViewProj, \n"+ " uniform float3 camPos, \n"+ " uniform float fadeGap, \n"+ " uniform float invisibleDist, \n" + " uniform float uScroll, \n"+ " uniform float vScroll, \n"+ " uniform float4 preRotatedQuad[4] ) \n"+ "{ \n"+ //Face the camera " float4 vCenter = float4( position.x, position.y, position.z, 1.0f ); \n"+ " float4 vScale = float4( normal.x, normal.y, normal.x, 1.0f ); \n"+ " oPosition = mul( worldViewProj, vCenter + (preRotatedQuad[normal.z] * vScale) ); \n"+ " oColor.rgb = color.rgb; \n"+ //Fade out in the distance " float dist = distance(camPos.xz, position.xz); \n"+ " oColor.a = (invisibleDist - dist) / fadeGap; \n"+ //UV scroll " oUv = uv; \n"+ " oUv.x += uScroll; \n"+ " oUv.y += vScroll; \n"+ //Fog " oFog.x = oPosition.z; \n"+ "}"; vertexShader2 = HighLevelGpuProgramManager.Instance.CreateProgram( "SpriteFade_vp", ResourceGroupManager.DefaultResourceGroupName, "cg", GpuProgramType.Vertex); vertexShader2.Source = vertexProg2; vertexShader2.SetParam("profiles", "vs_1_1 arbvp1"); vertexShader2.SetParam("entry_point", "SpriteFade_vp"); vertexShader2.Load(); } } } else { //Compatible billboard method mFallbackSet = mSceneMgr.CreateBillboardSet(GetUniqueID("SBS"), 100); mNode.AttachObject(mFallbackSet); } }
public string Get(object target) { BillboardOrigin o = ((BillboardParticleRenderer)target).BillboardOrigin; return(ScriptEnumAttribute.GetScriptAttribute((int)o, typeof(BillboardOrigin))); }