как можно сделать лучи света
, god rays sun rays
![]() |
Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
|
| ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
| [216.73.217.146] |
|
|
ПРАВИЛА РАЗДЕЛА · FAQ раздела Delphi · Книги по Delphi
как можно сделать лучи света
, god rays sun rays
|
Сообщ.
#1
,
|
|
|
|
|
|
|
|
|
столько времени прошло
Может кому пригодится: это не совсем то что я хотел , лучи есть, но они не от источника света ![]() ![]() procedure TForm1.VolumeRays; const NumOuterRays = 72; // Количество внешних цилиндров (лучей) OuterCylinderHeight = 80; // Высота внешнего конуса OuterCylinderBottomRadius = 0.1; // Толщина (радиус) каждого внешнего цилиндра OuterTotalRadius = 20; // Радиус основания внешнего конуса NumMiddleRays = 62; // Количество средних цилиндров MiddleCylinderHeight = 80; // Высота среднего конуса MiddleCylinderBottomRadius = 0.1; // Толщина (радиус) каждого среднего цилиндра MiddleTotalRadius = 10; // Радиус основания среднего конуса NumInnerRays = 52; // Количество внутренних цилиндров InnerCylinderHeight = 80; // Высота внутреннего конуса InnerCylinderBottomRadius = 0.1; // Толщина (радиус) каждого внутреннего цилиндра InnerTotalRadius = 5; // Радиус основания внутреннего конуса NumSmallestRays = 42; // Количество самых малых цилиндров SmallestCylinderHeight = 80; // Высота самого малого конуса SmallestCylinderBottomRadius = 0.1; // Толщина (радиус) каждого самого малого цилиндра SmallestTotalRadius = 3; // Радиус основания самого малого конуса var I: Integer; OuterRay, MiddleRay, InnerRay, SmallestRay: TGLCylinder; Angle, XPos, ZPos: Single; begin // Создание полупрозрачного материала GLMaterialLibrary1.Materials.Add; with GLMaterialLibrary1.Materials[1] do begin Material.Texture.Image.LoadFromFile('add\8143817.jpg'); // 8143817 volum Material.Texture.Disabled := False; Name := 'VolumeMaterial'; Material.BlendingMode :=bmTransparency; //bmTransparency; bmModulate; Material.FrontProperties.Ambient.Alpha := 0.1; Material.FrontProperties.Diffuse.Alpha := 0.1; Material.FrontProperties.Emission.Alpha := 0.1; Material.FrontProperties.Specular.Alpha:= 0.1; end; GLSLShader2.LoadShaderPrograms('add\sun.Vert', 'add\sun.Frag'); GLSLShader2.Enabled := true; GLMaterialLibrary1.LibMaterialByName('VolumeMaterial').Shader:=GLSLShader2; // Осветительный объект SunLight := TGLLightSource.CreateAsChild(GLScene1.Objects); SunLight.Position.SetPoint(0, 0, 0); SunLight.Diffuse.SetColor(1.0, 1.0, 0.0,0.1); // === Наружный конус (самый большой) === for I := 0 to Pred(NumOuterRays) do begin Angle := (I * 360 / NumOuterRays) * Pi / 180; OuterRay := TGLCylinder.CreateAsChild(SunLight); OuterRay.Height := OuterCylinderHeight; OuterRay.BottomRadius := OuterCylinderBottomRadius; OuterRay.TopRadius := OuterCylinderBottomRadius; XPos := OuterTotalRadius * Sin(Angle); ZPos := OuterTotalRadius * Cos(Angle); OuterRay.Position.SetPoint(XPos, -OuterCylinderHeight / 2, ZPos); OuterRay.Direction.SetVector(-XPos, OuterCylinderHeight, -ZPos); OuterRay.Direction.Normalize; OuterRay.Material.MaterialLibrary := GLMaterialLibrary1; OuterRay.Material.LibMaterialName := 'VolumeMaterial'; OuterRay.PitchAngle := 80; OuterRay.Parent := GLDummyCube2; // GLShadowVolume1.Occluders.AddCaster(OuterRay); end; // === Средний конус (среднего размера) === for I := 0 to Pred(NumMiddleRays) do begin Angle := (I * 360 / NumMiddleRays) * Pi / 180; MiddleRay := TGLCylinder.CreateAsChild(SunLight); MiddleRay.Height := MiddleCylinderHeight; MiddleRay.BottomRadius := MiddleCylinderBottomRadius; MiddleRay.TopRadius := MiddleCylinderBottomRadius; XPos := MiddleTotalRadius * Sin(Angle); ZPos := MiddleTotalRadius * Cos(Angle); MiddleRay.Position.SetPoint(XPos, -(OuterCylinderHeight / 2) + ((OuterCylinderHeight - MiddleCylinderHeight)/2), ZPos); MiddleRay.Direction.SetVector(-XPos, MiddleCylinderHeight, -ZPos); MiddleRay.Direction.Normalize; MiddleRay.Material.MaterialLibrary := GLMaterialLibrary1; MiddleRay.Material.LibMaterialName := 'VolumeMaterial'; MiddleRay.PitchAngle := 80; MiddleRay.Parent := GLDummyCube2; // GLShadowVolume1.Occluders.AddCaster(MiddleRay); MiddleRay.TurnAngle:=15; end; // === Внутренний конус (ещё меньше) === for I := 0 to Pred(NumInnerRays) do begin Angle := (I * 360 / NumInnerRays) * Pi / 180; InnerRay := TGLCylinder.CreateAsChild(SunLight); InnerRay.Height := InnerCylinderHeight; InnerRay.BottomRadius := InnerCylinderBottomRadius; InnerRay.TopRadius := InnerCylinderBottomRadius; XPos := InnerTotalRadius * Sin(Angle); ZPos := InnerTotalRadius * Cos(Angle); InnerRay.Position.SetPoint(XPos, -(OuterCylinderHeight / 2) + ((OuterCylinderHeight - InnerCylinderHeight)/2), ZPos); InnerRay.Direction.SetVector(-XPos, InnerCylinderHeight, -ZPos); InnerRay.Direction.Normalize; InnerRay.Material.MaterialLibrary := GLMaterialLibrary1; InnerRay.Material.LibMaterialName := 'VolumeMaterial'; InnerRay.PitchAngle := 80; InnerRay.Parent := GLDummyCube2; InnerRay.TurnAngle:=20; //GLShadowVolume1.Occluders.AddCaster(InnerRay); end; // === Самый маленький конус (совсем маленький) === for I := 0 to Pred(NumSmallestRays) do begin Angle := (I * 360 / NumSmallestRays) * Pi / 180; SmallestRay := TGLCylinder.CreateAsChild(SunLight); SmallestRay.Height := SmallestCylinderHeight; SmallestRay.BottomRadius := SmallestCylinderBottomRadius; SmallestRay.TopRadius := SmallestCylinderBottomRadius; XPos := SmallestTotalRadius * Sin(Angle); ZPos := SmallestTotalRadius * Cos(Angle); SmallestRay.Position.SetPoint(XPos, -(OuterCylinderHeight / 2) + ((OuterCylinderHeight - SmallestCylinderHeight)/2), ZPos); SmallestRay.Direction.SetVector(-XPos, SmallestCylinderHeight, -ZPos); SmallestRay.Direction.Normalize; SmallestRay.Material.MaterialLibrary := GLMaterialLibrary1; SmallestRay.Material.LibMaterialName := 'VolumeMaterial'; SmallestRay.PitchAngle := 80; SmallestRay.Parent := GLDummyCube2; SmallestRay.TurnAngle:=30; // GLShadowVolume1.Occluders.AddCaster(SmallestRay); end; end; |