public void Initialize(DeviceContextHolder contextHolder) { _effect = contextHolder.GetEffect<EffectDeferredGObject>(); if (_kn5Material == null) return; _txDiffuse = GetTexture("txDiffuse", contextHolder); _txNormal = _kn5Material.ShaderName.Contains("damage") ? null : GetTexture("txNormal", contextHolder); _txMaps = GetTexture("txMaps", contextHolder); _txDetails = GetTexture("txDetail", contextHolder); _txDetailsNormal = GetTexture("txNormalDetail", contextHolder); uint flags = 0; if (_txNormal != null) { flags |= EffectDeferredGObject.HasNormalMap; } if (_txMaps != null) { flags |= EffectDeferredGObject.HasMaps; } if (_kn5Material.GetPropertyValueAByName("useDetail") > 0) { flags |= EffectDeferredGObject.HasDetailsMap; } if (_txDetailsNormal != null) { flags |= EffectDeferredGObject.HasDetailsNormalMap; } if (_kn5Material.ShaderName == "ksTyres" || _kn5Material.ShaderName == "ksBrakeDisc") { flags |= EffectDeferredGObject.UseDiffuseAlphaAsMap; } if (IsBlending) { flags |= EffectDeferredGObject.AlphaBlend; } if (Equals(_kn5Material.GetPropertyValueAByName("isAdditive"), 1.0f)) { flags |= EffectDeferredGObject.IsAdditive; } var specularExp = _kn5Material.GetPropertyValueAByName("ksSpecularEXP"); if (Equals(_kn5Material.GetPropertyValueAByName("isAdditive"), 2.0f)) { specularExp = 250f; } _material = new EffectDeferredGObject.Material { Ambient = _kn5Material.GetPropertyValueAByName("ksAmbient"), Diffuse = _kn5Material.GetPropertyValueAByName("ksDiffuse"), Specular = _kn5Material.GetPropertyValueAByName("ksSpecular"), SpecularExp = specularExp, Emissive = _kn5Material.GetPropertyValueCByName("ksEmissive"), FresnelC = _kn5Material.GetPropertyValueAByName("fresnelC"), FresnelExp = _kn5Material.GetPropertyValueAByName("fresnelEXP"), FresnelMaxLevel = _kn5Material.GetPropertyValueAByName("fresnelMaxLevel"), DetailsUvMultipler = _kn5Material.GetPropertyValueAByName("detailUVMultiplier"), DetailsNormalBlend = _kn5Material.GetPropertyValueAByName("detailNormalBlend"), Flags = flags }; }
protected Kn5MaterialDeferred(EffectDeferredGObject.Material material, bool isBlending) { _material = material; IsBlending = isBlending; }
public void Initialize(DeviceContextHolder contextHolder) { _effect = contextHolder.GetEffect<EffectDeferredGObject>(); var texturesProvider = contextHolder.Get<TexturesProvider>(); _txDiffuse = texturesProvider.GetTexture(_filename, contextHolder); }
protected override void InitializeInner() { base.InitializeInner(); _materialsProvider = new MaterialsProviderDeferred(); _texturesProvider = new TexturesProvider(); DeviceContextHolder.Set(_materialsProvider); DeviceContextHolder.Set(_texturesProvider); Scene.Add(SkyObject.Create(500f)); IRenderableObject mainNode = null; foreach (var kn5 in _kn5) { if (mainNode == null) { _carHelper.SetKn5(DeviceContextHolder); } else { _materialsProvider.SetKn5(kn5); _texturesProvider.SetKn5(kn5.OriginalFilename, kn5); } var node = Kn5Converter.Convert(kn5.RootNode, DeviceContextHolder); Scene.Add(node); if (mainNode != null) continue; node.IsReflectable = false; mainNode = node; } var asList = mainNode as Kn5RenderableList; if (asList != null) { Scene.AddRange(_carHelper.LoadAmbientShadows(asList, 0.001f)); _carHelper.AdjustPosition(asList); _carHelper.LoadMirrors(asList, DeviceContextHolder); LoadLights(asList); } Scene.UpdateBoundingBox(); Camera = new CameraOrbit(32) { Alpha = 0.9f, Beta = 0.1f, NearZ = 0.2f, FarZ = 500f, Radius = mainNode?.BoundingBox?.GetSize().Length() * 1.2f ?? 4.8f, Target = (mainNode?.BoundingBox?.GetCenter() ?? Vector3.Zero) - new Vector3(0f, 0.05f, 0f) }; _resetCamera = (CameraOrbit)Camera.Clone(); Sun = new DirectionalLight { Color = FixLight(new Vector3(1.2f, 1.0f, 0.9f)) * 5f, Direction = Vector3.Normalize(new Vector3(-1.2f, -3.4f, -2.2f)) }; _effect = DeviceContextHolder.GetEffect<EffectDeferredGObject>(); }
public static void Set(this EffectVariable variable, EffectDeferredGObject.Material o) { SlimDxExtension.Set(variable, o, EffectDeferredGObject.Material.Stride); }