コード例 #1
0
ファイル: main.go プロジェクト: walesey/go-engine
func majicParticles() *effects.ParticleGroup {
	img, _ := assets.ImportImageCached("resources/majic.png")
	material := renderer.NewMaterial(renderer.NewTexture("diffuseMap", img, false))
	particleSystem := effects.CreateParticleSystem(effects.ParticleSettings{
		MaxParticles:     300,
		ParticleEmitRate: 700,
		BaseGeometry:     renderer.CreateBox(float32(1), float32(1)),
		TotalFrames:      9,
		FramesX:          3,
		FramesY:          3,
		MaxLife:          1.3,
		MinLife:          0.7,
		StartColor:       color.NRGBA{254, 254, 254, 254},
		EndColor:         color.NRGBA{254, 254, 254, 254},
		StartSize:        mgl32.Vec2{10, 10}.Vec3(0),
		EndSize:          mgl32.Vec2{10, 10}.Vec3(0),
		MinTranslation:   mgl32.Vec2{-1, -1}.Vec3(0),
		MaxTranslation:   mgl32.Vec2{1, 1}.Vec3(0),
		MinStartVelocity: mgl32.Vec2{-170, -170}.Vec3(0),
		MaxStartVelocity: mgl32.Vec2{170, 170}.Vec3(0),
		MaxRotation:      -3.14,
		MinRotation:      3.14,
	})
	particleSystem.FaceCamera = false
	particleGroup := effects.NewParticleGroup(nil, particleSystem)
	particleGroup.Node.Material = material
	return particleGroup
}
コード例 #2
0
ファイル: main.go プロジェクト: walesey/go-engine
func sparkParticles() *effects.ParticleGroup {
	img, _ := assets.ImportImageCached("resources/spark.png")
	material := renderer.NewMaterial(renderer.NewTexture("diffuseMap", img, false))
	particleSystem := effects.CreateParticleSystem(effects.ParticleSettings{
		MaxParticles:     80,
		ParticleEmitRate: 400,
		BaseGeometry:     renderer.CreateBox(float32(1), float32(1)),
		TotalFrames:      1,
		FramesX:          1,
		FramesY:          1,
		MaxLife:          3.3,
		MinLife:          1.7,
		StartColor:       color.NRGBA{254, 160, 90, 254},
		EndColor:         color.NRGBA{254, 160, 90, 254},
		StartSize:        mgl32.Vec2{2, 2}.Vec3(0),
		EndSize:          mgl32.Vec2{2, 2}.Vec3(0),
		MinTranslation:   mgl32.Vec2{-5, -5}.Vec3(0),
		MaxTranslation:   mgl32.Vec2{5, 5}.Vec3(0),
		MinStartVelocity: mgl32.Vec2{-100, -100}.Vec3(0),
		MaxStartVelocity: mgl32.Vec2{100, 100}.Vec3(0),
		Acceleration:     mgl32.Vec2{0, 400}.Vec3(0),
		OnParticleUpdate: func(p *effects.Particle) {
			p.Scale[0] = p.Scale[0] * (1 + p.Velocity.Len()*0.05)
			p.Orientation = mgl32.QuatBetweenVectors(mgl32.Vec3{1, 0, 0}, p.Velocity)
		},
	})
	particleSystem.FaceCamera = false
	particleGroup := effects.NewParticleGroup(nil, particleSystem)
	particleGroup.Node.Material = material
	return particleGroup
}
コード例 #3
0
ファイル: main.go プロジェクト: walesey/go-engine
func dustParticles() *effects.ParticleGroup {
	img, _ := assets.ImportImageCached("resources/smoke.png")
	material := renderer.NewMaterial(renderer.NewTexture("diffuseMap", img, false))
	particleSystem := effects.CreateParticleSystem(effects.ParticleSettings{
		MaxParticles:     5,
		ParticleEmitRate: 20,
		BaseGeometry:     renderer.CreateBox(float32(1), float32(1)),
		TotalFrames:      64,
		FramesX:          8,
		FramesY:          8,
		MaxLife:          3.3,
		MinLife:          2.7,
		StartColor:       color.NRGBA{254, 254, 254, 120},
		EndColor:         color.NRGBA{254, 254, 254, 0},
		StartSize:        mgl32.Vec2{40, 40}.Vec3(0),
		EndSize:          mgl32.Vec2{180, 180}.Vec3(0),
		MinTranslation:   mgl32.Vec2{-2, -2}.Vec3(0),
		MaxTranslation:   mgl32.Vec2{2, 2}.Vec3(0),
		MinStartVelocity: mgl32.Vec2{-5.0, -5.0}.Vec3(0),
		MaxStartVelocity: mgl32.Vec2{5.0, 5.0}.Vec3(0),
		MaxRotation:      -3.14,
		MinRotation:      3.14,
	})
	particleSystem.FaceCamera = false
	particleGroup := effects.NewParticleGroup(nil, particleSystem)
	particleGroup.Node.Material = material
	return particleGroup
}
コード例 #4
0
ファイル: main.go プロジェクト: walesey/go-engine
func setupScene(gameEngine engine.Engine, shader *renderer.Shader) {
	camera := gameEngine.Camera()

	transparentNode := renderer.NewNode()
	gameEngine.AddSpatialTransparent(transparentNode)
	transparentNode.RendererParams = &renderer.RendererParams{
		DepthTest:    true,
		Unlit:        true,
		Transparency: renderer.EMISSIVE,
	}

	// Sky cubemap
	skyImg, err := assets.ImportImage("TestAssets/cloudSky.jpg")
	if err == nil {
		skyImg = imaging.AdjustBrightness(skyImg, -30)
		skyImg = imaging.AdjustContrast(skyImg, 30)
		geom := renderer.CreateSkyBox()
		geom.Transform(mgl32.Scale3D(10000, 10000, 10000))
		skyNode := renderer.NewNode()
		skyNode.SetOrientation(mgl32.QuatRotate(1.57, mgl32.Vec3{0, 1, 0}))
		skyNode.Material = renderer.NewMaterial(renderer.NewTexture("diffuseMap", skyImg, false))
		skyNode.RendererParams = renderer.NewRendererParams()
		skyNode.RendererParams.CullBackface = false
		skyNode.RendererParams.Unlit = true
		skyNode.Add(geom)
		gameEngine.AddSpatial(skyNode)
		// create an environmentMap using the skybox texture
		envCubeMap := renderer.NewCubemap("environmentMap", skyImg, true)
		gameEngine.DefaultCubeMap(envCubeMap)
	}

	// load scene objs
	objs := []string{
		"TestAssets/wellScene/floor.obj",
		"TestAssets/wellScene/frame1.obj",
		"TestAssets/wellScene/frame2.obj",
		"TestAssets/wellScene/well.obj",
		"TestAssets/wellScene/torches.obj",
	}
	for _, objFile := range objs {
		if geom, mat, err := assets.ImportObjCached(objFile); err == nil {
			sceneNode := renderer.NewNode()
			sceneNode.Add(geom)
			sceneNode.Material = mat
			sceneNode.RendererParams = renderer.NewRendererParams()
			sceneNode.RendererParams.CullBackface = false
			gameEngine.AddSpatial(sceneNode)
		}
	}

	for i := 0; i < 2; i++ {
		torchLocation := mgl32.Vec3{0.86, 1.76, 1.05}
		if i == 1 {
			torchLocation = mgl32.Vec3{0.86, 1.76, -1.05}
		}

		fire := fireParticles()
		spark := sparkParticles()
		torchParticles := effects.NewParticleGroup(camera, fire, spark)
		torchParticles.SetTranslation(torchLocation)
		transparentNode.Add(torchParticles)
		gameEngine.AddUpdatable(torchParticles)

		light := renderer.NewLight(renderer.POINT)
		light.SetTranslation(torchLocation.Add(mgl32.Vec3{0, 0.05, 0}))
		gameEngine.AddLight(light)

		var x float64
		gameEngine.AddUpdatable(engine.UpdatableFunc(func(dt float64) {
			x += dt
			mag := float32(math.Abs(0.6*math.Sin(3*x)+0.3*math.Sin(4*x)+0.15*math.Sin(7*x)+0.1*math.Sin(15*x))) + 0.5
			mag *= 0.05
			light.Color = [3]float32{1 * mag, 0.6 * mag, 0.4 * mag}
		}))
	}
}