public override void GetLightCount(out int[] lightCount) { lightCount = new int[3] { 0, 0, 0 }; for (int i = 0; i < this.lightParamsList.Count; i++) { LightParams curParams = this.lightParamsList[i]; if (curParams.Type == LightType.Point) { lightCount[0]++; } else if (curParams.Type == LightType.Directional) { lightCount[1]++; } else if (curParams.Type == LightType.Spotlight) { lightCount[2]++; } } }
private static void InitLightsMop() { LightData.Load(@"DBFilesClient\LightData.dbc"); LightParams.Load(@"DBFilesClient\LightParams.dbc"); ZoneLight.Load(@"DBFilesClient\ZoneLight.dbc"); ZoneLightPoint.Load(@"DBFilesClient\ZoneLightPoint.dbc"); }
public static LightParams Lerp(LightParams from, LightParams to, float value) { LightParams lp; lp.color = Color.Lerp(from.color, to.color, value); lp.intensity = Mathf.Lerp(from.intensity, to.intensity, value); lp.range = Mathf.Lerp(from.range, to.range, value); return(lp); }
public LightParams Delta(LightParams lp) { LightParams lpDelta; lpDelta.color = color - lp.color; lpDelta.intensity = intensity - lp.intensity; lpDelta.range = range - lp.range; return(lpDelta); }
public override void SetLightCount(int[] currLightCount) { for (int type = 0; type < 3; type++) { for (int i = 0; i < currLightCount[type]; i++) { var curParam = new LightParams(); if (type == 0) { curParam.Type = LightType.Point; } else if (type == 1) { curParam.Type = LightType.Directional; } else if (type == 2) { curParam.Type = LightType.Spotlight; } this.lightParamsList.Add(curParam); } } }
internal static extern int LoadLight(IntPtr entPtr, int slot, LightParams lightParams);
private bool AddIlluminationInvocation(LightParams curLightParams, Function vsMain, int groupOrder, ref int internalCounter) { FunctionInvocation curFuncInvocation = null; //Merge dffuse color with vertex color if need to if ((this.trackVertexColorType & TrackVertexColor.Diffuse) == TrackVertexColor.Diffuse) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncModulate, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.vsDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } //Merge specular color with vertex color if need to if (this.specularEnable && (this.trackVertexColorType & TrackVertexColor.Specular) == TrackVertexColor.Specular) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncModulate, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.vsDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } switch (curLightParams.Type) { case LightType.Directional: if (this.specularEnable) { curFuncInvocation = new FunctionInvocation( FFPRenderState.FFPFuncLightDirectionDiffuseSpecular, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Direction, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.surfaceShininess, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } else { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightDirectionDiffuse, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Direction, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } break; case LightType.Point: if (this.specularEnable) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightPointDiffuseSpecular, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Position, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.AttenuatParams, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.surfaceShininess, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } else { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightPointDiffuse, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Position, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.AttenuatParams, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } break; case LightType.Spotlight: if (this.specularEnable) { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightSpotDiffuseSpecular, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Position, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.Direction, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.AttenuatParams, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.SpotParams, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.SpecularColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.surfaceShininess, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutSpecular, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } else { curFuncInvocation = new FunctionInvocation(FFPRenderState.FFPFuncLightSpotDiffuse, groupOrder, internalCounter++); curFuncInvocation.PushOperand(this.worldViewMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInPosition, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.worldViewITMatrix, Operand.OpSemantic.In); curFuncInvocation.PushOperand(this.vsInNormal, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.Position, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(curLightParams.AttenuatParams, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.SpotParams, Operand.OpSemantic.In); curFuncInvocation.PushOperand(curLightParams.DiffuseColor, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.In, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); curFuncInvocation.PushOperand(this.vsOutDiffuse, Operand.OpSemantic.Out, (Operand.OpMask.X | Operand.OpMask.Y | Operand.OpMask.Z)); vsMain.AddAtomInstance(curFuncInvocation); } break; } return(true); }
public override void UpdateGpuProgramsParams(Graphics.IRenderable rend, Graphics.Pass pass, Graphics.AutoParamDataSource source, Core.Collections.LightList lightList) { if (this.lightParamsList.Count == 0) { return; } Matrix4 matView = source.ViewMatrix; LightType curLightType = LightType.Directional; int curSearchLightIndex = 0; //Update per light parameters for (int i = 0; i < this.lightParamsList.Count; i++) { LightParams curParams = this.lightParamsList[i]; if (curLightType != curParams.Type) { curLightType = curParams.Type; curSearchLightIndex = 0; } Light srcLight = null; Vector4 vParameter; ColorEx color; //Search a matching light from the current sorted lights of the given renderable for (int j = curSearchLightIndex; j < lightList.Count; j++) { if (lightList[j].Type == curLightType) { srcLight = lightList[j]; curSearchLightIndex = j + 1; break; } } //No matching light found -> use a blank dummy light for parameter update if (srcLight == null) { srcLight = this.blankLight; } switch (curParams.Type) { case LightType.Directional: //Update light direction vParameter = matView.TransformAffine(srcLight.GetAs4DVector(true)); curParams.Direction.SetGpuParameter(vParameter); break; case LightType.Point: //Update light position vParameter = matView.TransformAffine(srcLight.GetAs4DVector(true)); curParams.Position.SetGpuParameter(vParameter); //Update light attenuation paramters vParameter.x = srcLight.AttenuationRange; vParameter.y = srcLight.AttenuationConstant; vParameter.z = srcLight.AttenuationLinear; vParameter.w = srcLight.AttenuationQuadratic; curParams.AttenuatParams.SetGpuParameter(vParameter); break; case LightType.Spotlight: { Vector3 vec3; Matrix3 matViewIT; source.InverseTransposeViewMatrix.Extract3x3Matrix(out matViewIT); //Update light position vParameter = matView.TransformAffine(srcLight.GetAs4DVector(true)); curParams.Position.SetGpuParameter(vParameter); vec3 = matViewIT * srcLight.DerivedDirection; vec3.Normalize(); vParameter.x = -vec3.x; vParameter.y = -vec3.y; vParameter.z = -vec3.z; vParameter.w = 0.0f; curParams.Direction.SetGpuParameter(vParameter); //Update light attenuation parameters vParameter.x = srcLight.AttenuationRange; vParameter.y = srcLight.AttenuationConstant; vParameter.z = srcLight.AttenuationLinear; vParameter.w = srcLight.AttenuationQuadratic; curParams.AttenuatParams.SetGpuParameter(vParameter); //Update spotlight parameters Real phi = Axiom.Math.Utility.Cos(srcLight.SpotlightOuterAngle * 0.5); Real theta = Axiom.Math.Utility.Cos(srcLight.SpotlightInnerAngle * 0.5); vec3.x = theta; vec3.y = phi; vec3.z = srcLight.SpotlightFalloff; curParams.SpotParams.SetGpuParameter(vec3); } break; } //Update diffuse color if ((this.trackVertexColorType & TrackVertexColor.Diffuse) == 0) { color = srcLight.Diffuse * pass.Diffuse; curParams.DiffuseColor.SetGpuParameter(color); } else { color = srcLight.Diffuse; curParams.DiffuseColor.SetGpuParameter(color); } //Update specular color if need to if (this.specularEnable) { //Update diffuse color if ((this.trackVertexColorType & TrackVertexColor.Specular) == 0) { color = srcLight.Specular * pass.Specular; curParams.SpecularColor.SetGpuParameter(color); } else { color = srcLight.Specular; curParams.SpecularColor.SetGpuParameter(color); } } } }
extern internal static int LoadLight(IntPtr entPtr, int slot, LightParams lightParams);
protected override void DoGazeEnter( GazeHit hit ) { startParams = LightParams.ToParams( gazeLight ); lightLerper.Lerp( startParams, lightToParams, lp=>lp.Apply(gazeLight), time ); }
public static extern IntPtr BindAttachmentToLight(IntPtr attachmentPtr, ref LightParams lightParams);
extern public static IntPtr BindAttachmentToLight(IntPtr attachmentPtr, ref LightParams lightParams);
extern public static int LoadLight(IntPtr entPtr, int slot, LightParams lightParams);
protected override void DoGazeExit(GazeHit hit) { var currLightParams = LightParams.ToParams(gazeLight); lightLerper.Lerp(currLightParams, startParams, lp => lp.Apply(gazeLight), time); }
protected override void DoGazeEnter(GazeHit hit) { startParams = LightParams.ToParams(gazeLight); lightLerper.Lerp(startParams, lightToParams, lp => lp.Apply(gazeLight), time); }