protected virtual void SetScreenUniforms(TerrainNode node, TerrainQuad quad, MaterialPropertyBlock matPropertyBlock) { double ox = quad.GetOX(); double oy = quad.GetOY(); double l = quad.GetLength(); Vector3d2 p0 = new Vector3d2(ox, oy, 0.0); Vector3d2 p1 = new Vector3d2(ox + l, oy, 0.0); Vector3d2 p2 = new Vector3d2(ox, oy + l, 0.0); Vector3d2 p3 = new Vector3d2(ox + l, oy + l, 0.0); Matrix4x4d corners = new Matrix4x4d(p0.x, p1.x, p2.x, p3.x, p0.y, p1.y, p2.y, p3.y, p0.z, p1.z, p2.z, p3.z, 1.0, 1.0, 1.0, 1.0); matPropertyBlock.AddMatrix(m_uniforms.screenQuadCorners, (m_localToScreen * corners).ToMatrix4x4()); Matrix4x4d verticals = new Matrix4x4d(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0); matPropertyBlock.AddMatrix(m_uniforms.screenQuadVerticals, (m_localToScreen * verticals).ToMatrix4x4()); }
private void ApplyToBlock(ref MaterialPropertyBlock block, ShaderIDs bids) { #if USE_PROPERTY_BLOCKS block.AddVector(bids.exposureIBL, exposures); block.AddVector(bids.exposureLM, exposuresLM); block.AddMatrix(bids.skyMatrix, skyMatrix); block.AddMatrix(bids.invSkyMatrix, invMatrix); block.AddVector(bids.skyMin, skyMin); block.AddVector(bids.skyMax, skyMax); if (specularCube) { block.AddTexture(bids.specCubeIBL, specularCube); } else { block.AddTexture(bids.specCubeIBL, blackCube); } block.AddVector(bids.SH[0], SH.cBuffer[0]); block.AddVector(bids.SH[1], SH.cBuffer[1]); block.AddVector(bids.SH[2], SH.cBuffer[2]); block.AddVector(bids.SH[3], SH.cBuffer[3]); block.AddVector(bids.SH[4], SH.cBuffer[4]); block.AddVector(bids.SH[5], SH.cBuffer[5]); block.AddVector(bids.SH[6], SH.cBuffer[6]); block.AddVector(bids.SH[7], SH.cBuffer[7]); block.AddVector(bids.SH[8], SH.cBuffer[8]); #endif }
protected override void SetScreenUniforms(TerrainNode node, TerrainQuad quad, MaterialPropertyBlock matPropertyBlock) { double ox = quad.GetOX(); double oy = quad.GetOY(); double l = quad.GetLength(); Vector3d2 p0 = new Vector3d2(ox, oy, R); Vector3d2 p1 = new Vector3d2(ox + l, oy, R); Vector3d2 p2 = new Vector3d2(ox, oy + l, R); Vector3d2 p3 = new Vector3d2(ox + l, oy + l, R); Vector3d2 pc = (p0 + p3) * 0.5; double l0 = 0.0, l1 = 0.0, l2 = 0.0, l3 = 0.0; Vector3d2 v0 = p0.Normalized(ref l0); Vector3d2 v1 = p1.Normalized(ref l1); Vector3d2 v2 = p2.Normalized(ref l2); Vector3d2 v3 = p3.Normalized(ref l3); Matrix4x4d deformedCorners = new Matrix4x4d(v0.x * R, v1.x * R, v2.x * R, v3.x * R, v0.y * R, v1.y * R, v2.y * R, v3.y * R, v0.z * R, v1.z * R, v2.z * R, v3.z * R, 1.0, 1.0, 1.0, 1.0); matPropertyBlock.AddMatrix(m_uniforms.screenQuadCorners, (m_localToScreen * deformedCorners).ToMatrix4x4()); Matrix4x4d deformedVerticals = new Matrix4x4d(v0.x, v1.x, v2.x, v3.x, v0.y, v1.y, v2.y, v3.y, v0.z, v1.z, v2.z, v3.z, 0.0, 0.0, 0.0, 0.0); matPropertyBlock.AddMatrix(m_uniforms.screenQuadVerticals, (m_localToScreen * deformedVerticals).ToMatrix4x4()); matPropertyBlock.AddVector(m_uniforms.screenQuadCornerNorms, new Vector4((float)l0, (float)l1, (float)l2, (float)l3)); Vector3d2 uz = pc.Normalized(); Vector3d2 ux = (new Vector3d2(0, 1, 0)).Cross(uz).Normalized(); Vector3d2 uy = uz.Cross(ux); Matrix4x4d ltow = node.GetLocalToWorld(); Matrix3x3d tangentFrameToWorld = new Matrix3x3d(ltow.m[0, 0], ltow.m[0, 1], ltow.m[0, 2], ltow.m[1, 0], ltow.m[1, 1], ltow.m[1, 2], ltow.m[2, 0], ltow.m[2, 1], ltow.m[2, 2]); Matrix3x3d m = new Matrix3x3d(ux.x, uy.x, uz.x, ux.y, uy.y, uz.y, ux.z, uy.z, uz.z); matPropertyBlock.AddMatrix(m_uniforms.tangentFrameToWorld, (tangentFrameToWorld * m).ToMatrix4x4()); }
public void OnWillRenderObject() { if (m_MatProps == null) { m_MatProps = new MaterialPropertyBlock(); } Camera cam = Camera.current; cam.depthTextureMode |= DepthTextureMode.Depth; m_MatProps.Clear(); m_MatProps.AddVector("_CameraLocalPos", transform.InverseTransformPoint(cam.transform.position)); m_MatProps.AddMatrix("_CameraToLocal", transform.worldToLocalMatrix * cam.transform.localToWorldMatrix); m_MatProps.AddVector("_Scale", transform.localScale); m_MatProps.AddFloat("_Brightness", m_Brightness); if (Application.isPlaying) { float time = Time.time; m_TimeElapsed += m_Speed * (time - m_LastFrameTime); m_LastFrameTime = time; Shader.SetGlobalFloat("_FireTime", m_StartTime + m_TimeElapsed); } else { Shader.SetGlobalFloat("_FireTime", m_StartTime); } renderer.SetPropertyBlock(m_MatProps); }
/* * Sets the shader uniforms that are necessary to project on screen the * given TerrainQuad. This method can set the uniforms that are specific to * the given quad. */ public virtual void SetUniforms(TerrainNode node, TerrainQuad quad, MaterialPropertyBlock matPropertyBlock) { if (matPropertyBlock == null || node == null || quad == null) { return; } double ox = quad.GetOX(); double oy = quad.GetOY(); double l = quad.GetLength(); double distFactor = (double)node.GetDistFactor(); int level = quad.GetLevel(); matPropertyBlock.AddVector(m_uniforms.offset, new Vector4((float)ox, (float)oy, (float)l, (float)level)); Vector3d2 camera = node.GetLocalCameraPos(); matPropertyBlock.AddVector(m_uniforms.camera, new Vector4((float)((camera.x - ox) / l), (float)((camera.y - oy) / l), (float)((camera.z - node.GetView().GetGroundHeight()) / (l * distFactor)), (float)camera.z)); Vector3d2 c = node.GetLocalCameraPos(); Matrix3x3d m = m_localToTangent * (new Matrix3x3d(l, 0.0, ox - c.x, 0.0, l, oy - c.y, 0.0, 0.0, 1.0)); matPropertyBlock.AddMatrix(m_uniforms.tileToTangent, m.ToMatrix4x4()); SetScreenUniforms(node, quad, matPropertyBlock); }
public void AddToMaterialPropertyBlock(MaterialPropertyBlock block) { Node first = this.first; int count = this.count; while (count-- > 0) { switch (first.type) { case PropType.Float: block.AddFloat(first.property, first.value.FLOAT); break; case PropType.Vector: block.AddVector(first.property, first.value.VECTOR); break; case PropType.Color: block.AddColor(first.property, first.value.COLOR); break; case PropType.Matrix: block.AddMatrix(first.property, first.value.MATRIX); break; } first = first.next; } }
static int AddMatrix(IntPtr L) { int count = LuaDLL.lua_gettop(L); Type[] types0 = { typeof(MaterialPropertyBlock), typeof(int), typeof(Matrix4x4) }; Type[] types1 = { typeof(MaterialPropertyBlock), typeof(string), typeof(Matrix4x4) }; if (count == 3 && LuaScriptMgr.CheckTypes(L, types0, 1)) { MaterialPropertyBlock obj = LuaScriptMgr.GetNetObject <MaterialPropertyBlock>(L, 1); int arg0 = (int)LuaScriptMgr.GetNumber(L, 2); Matrix4x4 arg1 = LuaScriptMgr.GetNetObject <Matrix4x4>(L, 3); obj.AddMatrix(arg0, arg1); return(0); } else if (count == 3 && LuaScriptMgr.CheckTypes(L, types1, 1)) { MaterialPropertyBlock obj = LuaScriptMgr.GetNetObject <MaterialPropertyBlock>(L, 1); string arg0 = LuaScriptMgr.GetString(L, 2); Matrix4x4 arg1 = LuaScriptMgr.GetNetObject <Matrix4x4>(L, 3); obj.AddMatrix(arg0, arg1); return(0); } else { LuaDLL.luaL_error(L, "invalid arguments to method: MaterialPropertyBlock.AddMatrix"); } return(0); }
// Token: 0x06004B62 RID: 19298 RVA: 0x0012667C File Offset: 0x0012487C public void AddToMaterialPropertyBlock(MaterialPropertyBlock block) { global::UIPanelMaterialPropertyBlock.Node next = this.first; int num = this.count; while (num-- > 0) { switch (next.type) { case global::UIPanelMaterialPropertyBlock.PropType.Float: block.AddFloat(next.property, next.value.FLOAT); break; case global::UIPanelMaterialPropertyBlock.PropType.Vector: block.AddVector(next.property, next.value.VECTOR); break; case global::UIPanelMaterialPropertyBlock.PropType.Color: block.AddColor(next.property, next.value.COLOR); break; case global::UIPanelMaterialPropertyBlock.PropType.Matrix: block.AddMatrix(next.property, next.value.MATRIX); break; } next = next.next; } }
public MaterialPropertyBlock CreatePropertiesBlock() { MaterialPropertyBlock material = new MaterialPropertyBlock(); material.AddVector(_idMinBounds, _minBounds); material.AddVector(_idMaxBounds, _maxBounds); material.AddMatrix(_idProjection, _projectionMatrixCached); material.AddMatrix(_idViewWorldLight, _viewWorldLight); material.AddMatrix(_idLocalRotation, _localRotation); material.AddMatrix(_idRotation, _rotation); material.AddColor(_idColorTint, colorTint); material.AddFloat(_idSpotExponent, spotExponent); material.AddFloat(_idConstantAttenuation, constantAttenuation); material.AddFloat(_idLinearAttenuation, linearAttenuation); material.AddFloat(_idQuadraticAttenuation, quadraticAttenuation); material.AddFloat(_idLightMultiplier, lightMultiplier); switch (shadowMode) { case ShadowMode.Realtime: renderer.sharedMaterial.SetTexture("_ShadowTexture", _depthTexture); break; case ShadowMode.Baked: break; case ShadowMode.None: renderer.sharedMaterial.SetTexture("_ShadowTexture", null); break; } #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 float far = camera.farClipPlane; float near = camera.nearClipPlane; float fov = camera.fieldOfView; #else float far = camera.far; float near = camera.near; float fov = camera.fov; #endif material.AddVector(_idLightParams, new Vector4(near, far, far - near, (camera.isOrthoGraphic) ? Mathf.PI : fov * 0.5f * Mathf.Deg2Rad)); return(material); }
void Start() { property_block = new MaterialPropertyBlock(); #if UNITY_4_3 property_block.AddMatrix("prev_Object2World", Matrix4x4.identity); #else property_block.SetMatrix("prev_Object2World", Matrix4x4.identity); #endif mesh_renderer = GetComponent <MeshRenderer>(); mesh_renderer.SetPropertyBlock(property_block); }
void OnWillRenderObject() { int last = prevObjToWorld.Length - 1; for (int i = last; i > 0; --i) { prevObjToWorld[i] = prevObjToWorld[i - 1]; } prevObjToWorld[0] = transform.localToWorldMatrix; #if UNITY_4_3 property_block.AddMatrix("prev_Object2World", prevObjToWorld[last]); #else property_block.SetMatrix("prev_Object2World", prevObjToWorld[last]); #endif mesh_renderer.SetPropertyBlock(property_block); }
public void AddToMaterialPropertyBlock(MaterialPropertyBlock block) { UIPanelMaterialPropertyBlock.Node node = this.first; int num = this.count; while (true) { int num1 = num; num = num1 - 1; if (num1 <= 0) { break; } switch (node.type) { case UIPanelMaterialPropertyBlock.PropType.Float: { block.AddFloat(node.property, [email protected]); break; } case UIPanelMaterialPropertyBlock.PropType.Vector: { block.AddVector(node.property, [email protected]); break; } case UIPanelMaterialPropertyBlock.PropType.Color: { block.AddColor(node.property, [email protected]); break; } case UIPanelMaterialPropertyBlock.PropType.Matrix: { block.AddMatrix(node.property, [email protected]); break; } } node = node.next; } }