Example #1
0
func (me *uberShaders) setShaderSourceFrag(job *uberShaderJob, fx *FxEffect, inputs map[string]bool) (fragSrc string, err error) {
	var (
		srcBody, srcHead ustr.Buffer
		i                int
		shid             string
		op               *FxProc
		ops              FxProcs
		shFunc           *uberShaderFunc
	)
	srcHead.Writeln("out vec3 out_Color;")
	allOps := []FxProcs{fx.FxProcs, fx.ext}
	for _, ops = range allOps {
		for i = 0; i < len(ops); i++ {
			if op = &ops[i]; op.Enabled {
				if shid = Core.Render.Fx.procFuncs[op.procID]; len(shid) == 0 {
					err = errf("uberShader.setShaderSourceFrag('%s') -- unknown fxProc ID '%s'", job.pname, op.procID)
					return
				}
				if shFunc = me.allFuncs.fragment[shid]; shFunc == nil {
					err = errf("uberShader.setShaderSourceFrag('%s') -- unknown fragment func '%s'", job.pname, shid)
					return
				}
				me.setShaderSourceEnsureFunc(op, shFunc, &srcBody, inputs)
				inputs[op.unifName("float", "MixWeight")] = true
				for shid, _ = range inputs {
					if job.quals[shid] = op.qualifiers(shid); len(job.quals[shid]) > 0 {
						job.quals[shid] = job.quals[shid] + " "
					}
				}
			}
		}
	}

	for shid, _ = range inputs {
		switch shid[:4] {
		case "uni_":
			uslice.StrAppendUnique(&job.progUnis, shid)
			srcHead.Writeln("uniform %s %s;", me.inoutTypeSpec(shid), shid)
		case "var_":
			srcHead.Writeln("%sin %s %s;", job.quals[shid], me.inoutTypeSpec(shid), shid)
		}
	}
	srcBody.Writeln("void main () {")
	srcBody.Writeln("\tvec3 vCol = vec3(0);")
	for _, ops = range allOps {
		for i = 0; i < len(ops); i++ {
			if op = &ops[i]; op.Enabled {
				shFunc = me.allFuncs.fragment[Core.Render.Fx.procFuncs[op.procID]]
				srcBody.Writeln("\tvCol = mix(vCol, %s%d(vCol), %s);", shFunc.name, op.procIndex, op.unifName("float", "MixWeight"))
			}
		}
	}
	srcBody.Writeln("\tout_Color = vCol;")
	srcBody.Writeln("}")
	fragSrc = srcHead.String() + "\n" + srcBody.String()
	return
}
Example #2
0
func (me *uberShaders) setShaderSourceVert(job *uberShaderJob, vertTech string, varyings map[string]bool) (vertSrc string, err error) {
	var (
		i                int
		srcBody, srcHead ustr.Buffer
		shFunc           *uberShaderFunc
		inout, fname     string
		outputs          = []string{"gl_Position"}
		inputs           = map[string]bool{}
	)
	for inout, _ = range varyings {
		if inout[:4] == "var_" {
			outputs = append(outputs, inout)
		}
	}
	for i, inout = range outputs {
		if fname = "vx_" + vertTech + "_" + inout; i > 0 {
			srcHead.Writeln("%sout %s %s;", job.quals[inout], me.inoutTypeSpec(inout), inout)
		}
		if shFunc = me.allFuncs.vertex[fname]; shFunc == nil {
			err = errf("uberShader.setShaderSourceVert('%s') -- unknown vertex func '%s'", job.pname, fname)
			return
		}
		me.setShaderSourceEnsureFunc(nil, shFunc, &srcBody, inputs)
	}
	for inout, _ = range inputs {
		switch inout[:4] {
		case "att_":
			uslice.StrAppendUnique(&job.progAtts, inout)
			srcHead.Writeln("in %s %s;", me.inoutTypeSpec(inout), inout)
		case "uni_":
			uslice.StrAppendUnique(&job.progUnis, inout)
			srcHead.Writeln("uniform %s %s;", me.inoutTypeSpec(inout), inout)
		}
	}
	srcBody.Writeln("void main () {")
	for _, inout = range outputs {
		srcBody.Writeln("\t%s = vx_%s_%s();", inout, vertTech, inout)
	}
	srcBody.Writeln("}")
	vertSrc = srcHead.String() + "\n" + srcBody.String()
	return
}
Example #3
0
func (me *uberShaders) processFuncs() {
	var (
		pref, pref2 string
		fn, fn2     *uberShaderFunc
		mp, mp2     *map[string]*uberShaderFunc
	)
	mps := me.allMaps()
	for pref, mp = range mps {
		for _, fn = range *mp {
			//	annotate other funcs depending on this func
			for _, fn2 = range *mp {
				if fn2 != fn && strings.Index(fn2.rawSrc, fn.name) > 0 {
					uslice.StrAppendUnique(&fn2.dependsOn, fn.name)
				}
			}
			if len(pref) == 0 {
				//	we're in the map of shared-funcs, so need to check all other maps for dep-on-fn too
				for pref2, mp2 = range mps {
					if pref2 != pref {
						for _, fn2 = range *mp2 {
							if fn2 != fn && strings.Index(fn2.rawSrc, fn.name) > 0 {
								uslice.StrAppendUnique(&fn2.dependsOn, fn.name)
							}
						}
					}
				}
			}
			//	annotate this func for any uniforms, varyings or attributes
			for _, pref = range []string{"att_", "uni_", "var_"} {
				for _, pref2 = range ustr.ExtractAllIdentifiers(fn.rawSrc, pref) {
					uslice.StrAppendUnique(&fn.allInputs, pref2)
				}
			}
		}
	}
}