Difference between revisions of "ShaderDX7simmaterials"

From SimsWiki
Jump to: navigation, search
(EP3-OFB)
(EP5-SS)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
EP0-OFB
+
EP5-SS
 
0xCD7FE87A
 
0xCD7FE87A
 
0x1C0532FA
 
0x1C0532FA
Line 6: Line 6:
 
0xFF2DDA40
 
0xFF2DDA40
 
# dx7simmaterials
 
# dx7simmaterials
 +
 +
set paramSpecies 0
  
 
define CreateSimPerPixelCompositingMaterialFixedFunction()
 
define CreateSimPerPixelCompositingMaterialFixedFunction()
Line 42: Line 44:
 
ffIdentityModelTransform  #if skinning has happened, reset the FF xform
 
ffIdentityModelTransform  #if skinning has happened, reset the FF xform
 
  alphaTest true 128
 
  alphaTest true 128
  alphaTestFunction acceptIfGreaterOrEqual
+
  alphaTestFunction acceptIfGreaterOrEqual  
 
 
 
  #colorWriteEnable -red false -green false -blue false -alpha false
 
  #colorWriteEnable -red false -green false -blue false -alpha false
Line 83: Line 85:
 
endif
 
endif
  
       seti layerToAdd ($simHairFlag ? 3 : 7)
+
       seti layerToAdd ($simHairFlag ? 3 : 17)
 
 
  seti layerNumber ($stdMatLayer * 8 + (strcmp("${stdMatAlphaBlendMode}", "none") = 0 ? 0 : $layerToAdd))
+
  seti layerNumber ($stdMatLayer * 18 + (strcmp("${stdMatAlphaBlendMode}", "none") = 0 ? 0 : $layerToAdd))
 
 
 
shader -layer $layerNumber
 
shader -layer $layerNumber
Line 104: Line 106:
 
create DX7GhostPass()
 
create DX7GhostPass()
 
endif
 
endif
+
 
+
pass -fixedFunction
+
  
 +
    pass -fixedFunction           
 
if ($ghostPass = false)
 
if ($ghostPass = false)
 
               if ($doSkinning or $doMorphing)
 
               if ($doSkinning or $doMorphing)
Line 113: Line 114:
 
               endif
 
               endif
 
endif
 
endif
+
 
 
if ($simHairFlag)
 
if ($simHairFlag)
 
create SimHairAlphaState($stdMatAlphaBlendMode)
 
create SimHairAlphaState($stdMatAlphaBlendMode)
Line 119: Line 120:
 
create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
 
create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
 
endif
 
endif
+
 
+
 
  
 
             if ($doSkinning or $doMorphing)
 
             if ($doSkinning or $doMorphing)
Line 127: Line 128:
  
 
create LightingStatesParam(hasDeformations false)
 
create LightingStatesParam(hasDeformations false)
+
 
 
# this line should pull the lighting back into the 'bad value' range, see sims.matshad for a history.
 
# this line should pull the lighting back into the 'bad value' range, see sims.matshad for a history.
 
setv3 scale ($simMaterialLightingScale*0.5,$simMaterialLightingScale*0.5,$simMaterialLightingScale*0.5)
 
setv3 scale ($simMaterialLightingScale*0.5,$simMaterialLightingScale*0.5,$simMaterialLightingScale*0.5)
 
# original screw-up (my fault)
 
# original screw-up (my fault)
 
#setv3 scale (0.4,0.4,0.4)
 
#setv3 scale (0.4,0.4,0.4)
+
 
setv3 evalDiffuse (($stdMatDiffCoef).xyz * $scale)
+
setv3 evalDiffuse (($stdMatDiffCoef).xyz * $scale)
+
 
+
ffMatCoef -applyShapeColor $stdMatShapeColorIndex -diff $evalDiffuse -diffAlpha 1 -spec (0,0,0) -specPow 0 -amb $evalDiffuse -emit (0,0,0)    
ffMatCoef -applyShapeColor $stdMatShapeColorIndex -diff $evalDiffuse -diffAlpha 1 -spec (0,0,0) -specPow 0 -amb $evalDiffuse -emit (0,0,0)
+
 
+
             if ($stdMatBaseTextureEnabled)                          
             if ($stdMatBaseTextureEnabled)          
+
             
 
               stage
 
               stage
                   texture $stdMatBaseTextureName
+
                   texture $stdMatBaseTextureName                
                   ffTextureCoordsSource 0
+
                   ffTextureCoordsSource 0                                        
                   textureBlend multiplyScale2(texture diffuse) multiply(texture diffuse)
+
                    
 +
                  if ((viewerRenderType = $kViewerRenderTypeFamilyThumbnail) and (strcmp("${paramSpecies}", "0") != 0))
 +
                    textureBlend multiplyScale2(texture diffuse) select(diffuse)
 +
                  else
 +
                    textureBlend multiplyScale2(texture diffuse) multiply(texture diffuse)
 +
                  endif                                   
 
                   textureAddressing clamp clamp clamp
 
                   textureAddressing clamp clamp clamp
               end
+
               end                            
 +
                                                                   
 
             else
 
             else
                colorScalar ($stdMatDiffCoef) 1
+
              colorScalar ($stdMatDiffCoef) 1
                stage
+
              stage
                   textureBlend multiplyScale2(colorScalar diffuse) multiply(diffuse colorScalar)
+
                   textureBlend multiplyScale2(colorScalar diffuse) multiply(diffuse colorScalar)                
                end
+
              end
               
+
                 
 
             endif
 
             endif
 
              
 
              
 
             #  no stage = diffuse only
 
             #  no stage = diffuse only
 
end
 
 
 
+
end
 +
           
 
if (strcmp("${stdMatEnvCubeMode}", "reflection") = 0 and $alphaBlendingFlag = false)
 
if (strcmp("${stdMatEnvCubeMode}", "reflection") = 0 and $alphaBlendingFlag = false)
 
pass -fixedFunction
 
pass -fixedFunction
Line 177: Line 183:
 
 
 
end #pass
 
end #pass
endif
+
endif
+
 
+
 
end #shader
 
end #shader
 
   
 
   

Latest revision as of 09:40, 10 July 2007

EP5-SS
0xCD7FE87A
0x1C0532FA
0xA96CDD81
0xFF2DDA40
# dx7simmaterials

set paramSpecies 0

define CreateSimPerPixelCompositingMaterialFixedFunction()
   
   material
   
			
		#trace "Dx7	sim	skin: $currentMaterialName"
	
		shader 
			validateRenderShaderContext	-vertexFormat position 0 required
			validateRenderShaderContext	-vertexFormat normal 0 required
			validateRenderShaderContext	-vertexFormat texcoord 0 required
			validateRenderShaderContext	-viewerRenderType viewerRenderType

			create SetupSkinningStateAndPredicates()
			create SetupMorphingStateAndPredicates()

			# composite	all	layers into	offscreen buffer.
			arrayCreate	SimSkinCompositingSingleLayerPassFixedFunction $numTexturesToComposite

			# use composited texture in	a final	pass with lighting and so forth.
			create SimSkinFixedFunction()
			
		end	#shader	
	  
   end #material
enddef


define DX7GhostPass()

   
	pass -fixedFunction
		create PreprocessVertexShader()	 #skin if needed
		ffIdentityModelTransform  #if skinning has happened, reset the FF xform
	  alphaTest	true 128
	  alphaTestFunction	acceptIfGreaterOrEqual	  
	
	  #colorWriteEnable -red	false -green false -blue false -alpha false
	  alphaBlend srcFactor(zero) add dstFactor(one)
	  
	  #	sample the composited or base texture and push it to alpha
	  stage
			texture	$stdMatBaseTextureName
			ffTextureCoordsSource 0
			textureBlend select(texture) select(texture)
         textureAddressing clamp clamp clamp
		end	

   end


enddef




define SimStandardMaterialFixedFunction()

   setb	alphaBlendingFlag false
   setb	ghostPass false
   

   material
   
		#trace "Dx7	sim	standard: $currentMaterialName"

		if (numLightsOfType(${kShapeColorLight}) !=	0)
			seti stdMatShapeColorIndex 0
			set	stdMatAlphaBlendMode blend
			setb ghostPass true
		endif
		
		if (strcmp("${stdMatAlphaBlendMode}","blend") =	0)
			setb alphaBlendingFlag true	
		endif

      seti	layerToAdd ($simHairFlag ? 3 : 17)
					
	   seti	 layerNumber ($stdMatLayer * 18 + (strcmp("${stdMatAlphaBlendMode}",	"none")	= 0	? 0	: $layerToAdd))
	
		shader -layer $layerNumber

         create SupportedRenderShaderContextFFPredicates()   # to prevent unnecessary re-creation of FF shaders

			validateRenderShaderContext	-vertexFormat texcoord 0 required
			validateRenderShaderContext	-vertexFormat position 0 required
			validateRenderShaderContext	-vertexFormat normal 0 required

			validateRenderShaderContext	-viewerRenderType viewerRenderType

	
			create SetupSkinningStateAndPredicates()
			create SetupMorphingStateAndPredicates()
			
			if ($ghostPass)
				create DX7GhostPass()
			endif
				  	 

     		pass -fixedFunction            
				if ($ghostPass = false)
               if ($doSkinning or $doMorphing)
                  create PreprocessVertexShader()	#skin if needed
               endif
				endif
   			
				if ($simHairFlag)
					create SimHairAlphaState($stdMatAlphaBlendMode)
				else
					create StandardShaderFBAlphaState($stdMatAlphaBlendMode)
				endif
   			
   			

            if ($doSkinning or $doMorphing)
				   ffIdentityModelTransform  #if skinning has happened, reset the FF xform
				endif

				create LightingStatesParam(hasDeformations false)
   			
				# this line	should pull	the	lighting back into the 'bad	value' range, see sims.matshad for a history.
				setv3 scale	($simMaterialLightingScale*0.5,$simMaterialLightingScale*0.5,$simMaterialLightingScale*0.5)
				# original screw-up	(my	fault)
				#setv3 scale (0.4,0.4,0.4)
   		
				setv3 evalDiffuse (($stdMatDiffCoef).xyz * $scale)								
   			
				ffMatCoef -applyShapeColor $stdMatShapeColorIndex -diff	 $evalDiffuse -diffAlpha 1 -spec (0,0,0) -specPow 0	-amb $evalDiffuse -emit	(0,0,0)   							   
   							
            if ($stdMatBaseTextureEnabled)                           
               
               stage
                  texture	$stdMatBaseTextureName                  
                  ffTextureCoordsSource 0                                         
                  
                  if ((viewerRenderType = $kViewerRenderTypeFamilyThumbnail) and (strcmp("${paramSpecies}", "0") != 0))
                     textureBlend multiplyScale2(texture	diffuse) select(diffuse)
                  else
                     textureBlend multiplyScale2(texture	diffuse) multiply(texture diffuse)
                  endif                                     
                  textureAddressing clamp clamp clamp
               end                             
                                                                     
            else
               colorScalar ($stdMatDiffCoef) 1
               stage
                  textureBlend multiplyScale2(colorScalar diffuse) multiply(diffuse colorScalar)                  
               end
                  
            endif
            
            #  no stage = diffuse only
			
		end			
	            				
			if (strcmp("${stdMatEnvCubeMode}", "reflection") = 0 and $alphaBlendingFlag	= false)
				pass -fixedFunction
					alphaBlend srcFactor(srcAlpha) add dstFactor(one)
					if ($doSkinning or $doMorphing)
				      ffIdentityModelTransform  #if skinning has happened, reset the FF xform
				   endif
					ffMatCoef -diff	 (0,0,0) -diffAlpha	1 -spec	(0,0,0)	-specPow 0 -amb	(0,0,0)	-emit (0,0,0)
					create LightingStatesParam(false false)
					colorScalar	$stdMatEnvCubeCoef 1 -applyShapeColor $stdMatShapeColorIndex
					stage
						textureTransformType vector3
						ffTextureMatrix
						ffTextureCoordsSource fromReflectionVector
						textureAddressing clamp	clamp clamp
						textureBlend multiply(colorScalar texture) select(colorScalar)
						texture	$stdMatEnvCubeTextureName
					end	
				
				end	#pass
			endif						
						
					
		end	#shader	
	  
     
     
   if ($appInDebugMode = false)
     
      shader -layer $layerNumber

         create SupportedRenderShaderContextFFPredicates()   # to prevent unnecessary re-creation of FF shaders

			validateRenderShaderContext	-vertexFormat texcoord 0 required
			validateRenderShaderContext	-vertexFormat position 0 required
			validateRenderShaderContext	-vertexFormat normal 0 required

			validateRenderShaderContext	-viewerRenderType viewerRenderType


			create SetupSkinningStateAndPredicates()
			create SetupMorphingStateAndPredicates()
			
			pass -fixedFunction

            if ($doSkinning or $doMorphing)
               create PreprocessVertexShader()	#skin if needed
            endif

				ffIdentityModelTransform  #if skinning has happened, reset the FF xform

				create LightingStatesParam(hasDeformations false)
				
				# this line	should pull	the	lighting back into the 'bad	value' range, see sims.matshad for a history.
				setv3 scale	($simMaterialLightingScale*0.5,$simMaterialLightingScale*0.5,$simMaterialLightingScale*0.5)
				# original screw-up	(my	fault)
				#setv3 scale (0.4,0.4,0.4)
			
				setv3 evalDiffuse (($stdMatDiffCoef).xyz * $scale)
				
				
				ffMatCoef -applyShapeColor $stdMatShapeColorIndex -diff	 $evalDiffuse -diffAlpha 1 -spec (0,0,0) -specPow 0	-amb $evalDiffuse -emit	(0,0,0)
				
            colorScalar (1,1,1) 1
            stage
               textureBlend multiplyScale2(diffuse colorScalar) select(colorScalar)
            end
                
            
            
            #  no stage = diffuse only
				
			end
			
			

		end	#shader	
	  
   endif # debug mode check
     
     
     
     
   end #material
enddef


define CreateSimStandardMaterialFixedFunction()
   
	if (viewerRenderType = $kRenderTypeShadow)
		create SimShadowDX7()
	else
		create SimStandardMaterialFixedFunction()
	endif
	
enddef



define SimSkinCompositingSingleLayerPassFixedFunction(layer	n)

	pass #-fixedFunction
	
		renderClipSpaceRect
		
		
		# setting 'really small' textures to composite into	for	the	GF2	for	now.
		renderTarget simSkinCompositedBaseTexture -fixed (256, 256)	-bppHint 32	-alphaBitsHint 8 -allocateDepthBuffer false

	#	ffIdentityModelTransform  #if skinning has happened, reset the FF xform
#		ffMatCoef -diff	(1,1,1)	-diffAlpha 1 -spec (0,0,0) -specPow	0


		# passthrough SWVS until I can get all identity	matrix mode	for	the	FF case.
		
		shaderProgram -target vertexProgram	-method	assemble
			shaderSource
				vs_1_1
				dcl_position v0
				dcl_texcoord v1
				mov	oPos, v0
				mov	oT0, v1
			endShaderSource
		end
		
		if (&layer > 0)
			alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
			depthTest false	-enableDepthWrite false
			alphaTest true 1
			alphaTestFunction acceptIfGreaterOrEqual
		endif
		
		colorScalar	(1,1,1,	0)
		
		if (strcmp("${baseTexture&{layer}}","")	!= 0)
			stage
				texture	"${baseTexture&{layer}}"
				#ffTextureCoordsSource 0
				textureBlend select(texture) select(texture)
			end	
		else
			stage
				textureBlend select(colorScalar) select(colorScalar)
			end
		endif
		
	end	#pass

enddef



define SimSkinFixedFunction()


	pass -fixedFunction
		
		renderTarget viewerRenderTarget
		
		if (strcmp("${stdMatAlphaBlendMode}", "blend")=	0)
			alphaBlend srcFactor(srcAlpha) add dstFactor(invSrcAlpha)
			alphaTest true 128
			alphaTestFunction acceptIfGreaterOrEqual
		endif
		
		if ($doSkinning)		
			create PreprocessVertexShader()	 #skin if needed
			ffIdentityModelTransform  #if skinning has happened, reset the FF xform
		endif
		
		create LightingStatesParam(hasDeformations false)

		setv3 finalShaderDiffuse (($stdMatDiffCoef).xyz)

		ffMatCoef -applyShapeColor $stdMatShapeColorIndex -diff	($finalShaderDiffuse) -diffAlpha 1 -spec (0,0,0) -specPow 0	-amb (0.5,0.5,0.5) -emit (0,0,0)
		
		stage
			texture	simSkinCompositedBaseTexture
			#ffTextureCoordsSource 0
			textureBlend multiplyScale2(texture	diffuse) multiply(texture diffuse)
         textureAddressing clamp clamp clamp
		end	
		
	end	#pass
	
enddef




define SimShadowDX7()

   material
   
		#trace "Dx7	sim	shadow:	$currentMaterialName"
	
		shader 
			vertexFormatPred position 0	true

			viewerRenderTypePred $kRenderTypeShadow

			create SetupSkinningStateAndPredicates()
			create SetupMorphingStateAndPredicates()
			
			setb $doMorphing false
			setb $stdMatReduceBoneWeights true
			
			pass -fixedFunction
				create PreprocessVertexShader()	 #skin if needed

				ffIdentityModelTransform  #if skinning has happened, reset the FF xform

				ffMatCoef -diff	(1,1,1,1) -diffAlpha 1 -spec (0,0,0) -specPow 0	-amb (0,0,0,0)
					
				colorScalar	$stdMatShadowColor 1
				
				stage
					textureBlend select(colorScalar) select(colorScalar)
				end	
								
			end	#pass

		end	#shader	
	  
   end #material
enddef
Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox