mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Got hardware shadows in Cg working, for real this time
This commit is contained in:
parent
3339395d5b
commit
cde115a055
@ -237,7 +237,7 @@ correct_time(double time) {
|
||||
// A step backward in the high-precision clock, or more than a
|
||||
// small jump on only one of the clocks, is cause for alarm.
|
||||
|
||||
express_cat.warning()
|
||||
express_cat.debug()
|
||||
<< "Clock error detected; elapsed time " << time_delta
|
||||
<< "s on high-resolution counter, and " << tod_delta
|
||||
<< "s on time-of-day clock.\n";
|
||||
|
@ -6247,12 +6247,13 @@ specify_texture(Texture *tex) {
|
||||
GLP(TexParameteri)(target, GL_TEXTURE_MAG_FILTER,
|
||||
get_texture_filter_type(magfilter, true));
|
||||
|
||||
if (_supports_shadow_filter) {
|
||||
if (tex->get_format() == Texture::F_depth_component) {
|
||||
if (tex->get_format() == Texture::F_depth_component) {
|
||||
GLP(TexParameteri)(target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);
|
||||
if (_supports_shadow_filter) {
|
||||
if ((tex->get_magfilter() == Texture::FT_shadow) ||
|
||||
(tex->get_minfilter() == Texture::FT_shadow)) {
|
||||
GLP(TexParameteri)(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
|
||||
GLP(TexParameteri)(target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_GEQUAL);
|
||||
GLP(TexParameteri)(target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
|
||||
} else {
|
||||
GLP(TexParameteri)(target, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE);
|
||||
GLP(TexParameteri)(target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
|
||||
|
@ -79,6 +79,7 @@ CLP(ShaderContext)(ShaderExpansion *s, GSG *gsg) : ShaderContext(s) {
|
||||
_cg_profile[SHADER_type_frag] = CG_PROFILE_UNKNOWN;
|
||||
_cg_program[SHADER_type_vert] = (CGprogram)0;
|
||||
_cg_program[SHADER_type_frag] = (CGprogram)0;
|
||||
_cg_program[2] = (CGprogram)0;
|
||||
|
||||
if (header == "//Cg") {
|
||||
// Create the Cg context.
|
||||
@ -248,15 +249,32 @@ try_cg_compile(ShaderExpansion *s, GSG *gsg)
|
||||
return false;
|
||||
}
|
||||
|
||||
#if DEBUG_GL_SHADER
|
||||
// DEBUG: output the generated program
|
||||
{
|
||||
const char *program;
|
||||
program = cgGetProgramString (_cg_program[1], CG_COMPILED_PROGRAM);
|
||||
|
||||
GLCAT.debug() << program << "\n";
|
||||
bool success = true;
|
||||
CGparameter parameter;
|
||||
for (int progindex=0; progindex<2; progindex++) {
|
||||
int nvtx = _var_spec.size();
|
||||
for (parameter = cgGetFirstLeafParameter(_cg_program[progindex],CG_PROGRAM);
|
||||
parameter != 0;
|
||||
parameter = cgGetNextLeafParameter(parameter)) {
|
||||
CGenum vbl = cgGetParameterVariability(parameter);
|
||||
if ((vbl==CG_VARYING)||(vbl==CG_UNIFORM)) {
|
||||
success &= compile_parameter(parameter,
|
||||
cgGetParameterName(parameter),
|
||||
cg_type_to_panda_type(cgGetParameterType(parameter)),
|
||||
cg_dir_to_panda_dir(cgGetParameterDirection(parameter)),
|
||||
(vbl == CG_VARYING),
|
||||
GLCAT.get_safe_ptr());
|
||||
}
|
||||
}
|
||||
if ((progindex == SHADER_type_frag) && (nvtx != _var_spec.size())) {
|
||||
GLCAT.error() << "Cannot use vtx parameters in an fshader\n";
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
release_resources();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// The following code is present to work around a bug in the Cg compiler.
|
||||
// It does not generate correct code for shadow map lookups when using arbfp1.
|
||||
@ -269,7 +287,8 @@ try_cg_compile(ShaderExpansion *s, GSG *gsg)
|
||||
bool anyshadow = false;
|
||||
memset(shadowunit, 0, sizeof(shadowunit));
|
||||
vector_string lines;
|
||||
tokenize(cgGetProgramString(_cg_program[1], CG_COMPILED_PROGRAM), lines, "\n");
|
||||
tokenize(cgGetProgramString(_cg_program[SHADER_type_frag],
|
||||
CG_COMPILED_PROGRAM), lines, "\n");
|
||||
// figure out which texture units contain shadow maps.
|
||||
for (int lineno=0; lineno<(int)lines.size(); lineno++) {
|
||||
if (lines[lineno].compare(0,21,"#var sampler2DSHADOW ")) {
|
||||
@ -318,10 +337,10 @@ try_cg_compile(ShaderExpansion *s, GSG *gsg)
|
||||
for (int lineno=1; lineno<(int)lines.size(); lineno++) {
|
||||
result += (lines[lineno] + "\n");
|
||||
}
|
||||
cgDestroyProgram(_cg_program[1]);
|
||||
_cg_program[1] =
|
||||
_cg_program[2] = _cg_program[SHADER_type_frag];
|
||||
_cg_program[SHADER_type_frag] =
|
||||
cgCreateProgram(_cg_context, CG_OBJECT, result.c_str(),
|
||||
_cg_profile[1], "fshader", (const char**)NULL);
|
||||
_cg_profile[SHADER_type_frag], "fshader", (const char**)NULL);
|
||||
report_cg_compile_errors(s->get_name(), _cg_context);
|
||||
if (_cg_program[SHADER_type_frag]==0) {
|
||||
release_resources();
|
||||
@ -330,33 +349,6 @@ try_cg_compile(ShaderExpansion *s, GSG *gsg)
|
||||
}
|
||||
}
|
||||
|
||||
bool success = true;
|
||||
CGparameter parameter;
|
||||
for (int progindex=0; progindex<2; progindex++) {
|
||||
int nvtx = _var_spec.size();
|
||||
for (parameter = cgGetFirstLeafParameter(_cg_program[progindex],CG_PROGRAM);
|
||||
parameter != 0;
|
||||
parameter = cgGetNextLeafParameter(parameter)) {
|
||||
CGenum vbl = cgGetParameterVariability(parameter);
|
||||
if ((vbl==CG_VARYING)||(vbl==CG_UNIFORM)) {
|
||||
success &= compile_parameter(parameter,
|
||||
cgGetParameterName(parameter),
|
||||
cg_type_to_panda_type(cgGetParameterType(parameter)),
|
||||
cg_dir_to_panda_dir(cgGetParameterDirection(parameter)),
|
||||
(vbl == CG_VARYING),
|
||||
GLCAT.get_safe_ptr());
|
||||
}
|
||||
}
|
||||
if ((progindex == SHADER_type_frag) && (nvtx != _var_spec.size())) {
|
||||
GLCAT.error() << "Cannot use vtx parameters in an fshader\n";
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
release_resources();
|
||||
return false;
|
||||
}
|
||||
|
||||
cgGLLoadProgram(_cg_program[SHADER_type_vert]);
|
||||
cgGLLoadProgram(_cg_program[SHADER_type_frag]);
|
||||
|
||||
@ -392,6 +384,7 @@ release_resources() {
|
||||
_cg_profile[SHADER_type_frag] = (CGprofile)0;
|
||||
_cg_program[SHADER_type_vert] = (CGprogram)0;
|
||||
_cg_program[SHADER_type_frag] = (CGprogram)0;
|
||||
_cg_program[2] = (CGprogram)0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ private:
|
||||
#ifdef HAVE_CGGL
|
||||
CGcontext _cg_context;
|
||||
CGprofile _cg_profile[2];
|
||||
CGprogram _cg_program[2];
|
||||
CGprogram _cg_program[3];
|
||||
|
||||
void report_cg_compile_errors(const string &file, CGcontext ctx);
|
||||
bool try_cg_compile(ShaderExpansion *s, GSG *gsg);
|
||||
|
Loading…
x
Reference in New Issue
Block a user